From 534d5769bfa1346f76a3041eda3fd6f3d8bcebcc Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 21:49:30 +0900 Subject: [PATCH 01/16] Add NULL check when prelaunching default assistant Change-Id: Id8d6fa2323000101f4edd8ce33ab99d1bb8cae29 --- src/service_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index 966c336..4dda21b 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -950,7 +950,8 @@ int CServiceMain::prelaunch_default_assistant() if (prelaunch_mode && *prelaunch_mode) { const char *default_assistant = NULL; if (0 == mServicePlugin.get_default_assistant(&default_assistant)) { - if (!(mApplicationManager.is_application_running(default_assistant))) { + if (default_assistant && + !(mApplicationManager.is_application_running(default_assistant))) { MAS_LOGD("prelaunching default_assistant_appid : %s", default_assistant); launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH); } -- 2.7.4 From 6b0de0db125800e4958f95b863452b1a0e914389 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 21:50:03 +0900 Subject: [PATCH 02/16] Bump version to 0.2.32 Change-Id: I6ffb0f3d69404b37a450e6c51d0cad1351acb73d --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 418edad..7c451d8 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 89704e5..68165fa 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.31 +Version: 0.2.32 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 68e0b4f06b2c39decfa3d96d3d4cda89b380ad76 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 11:35:05 +0900 Subject: [PATCH 03/16] Enable app_manager_is_running and add retry logic on failure Change-Id: I3f32c7e8ef93e96b1ca57276c89748e3f11e6e4a --- src/multi_assistant_service.c | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 8ae416a..6438333 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -923,17 +923,21 @@ int mas_get_client_pid_by_appid(const char *appid) } } -#ifdef CHECK_APP_IS_RUNNING + int retry_num = 0; + bool succeeded = false; bool running = false; - if (appid && 0 == app_manager_is_running(appid, &running)) { - if (!running) { - MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", - (appid ? appid : "NULL"), ret, running); - mas_client_deinitialize(ret); - ret = -1; - } + if (appid) { + do { + succeeded = (0 == app_manager_is_running(appid, &running)); + if (succeeded && !running) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", + (appid ? appid : "NULL"), ret, running); + mas_client_deinitialize(ret); + ret = -1; + } + if (!succeeded) usleep(10000); + } while(!succeeded && retry_num++ < 3); } -#endif return ret; } @@ -948,17 +952,21 @@ const char* mas_get_client_appid_by_pid(int pid) ret = client->appid; } -#ifdef CHECK_APP_IS_RUNNING + int retry_num = 0; + bool succeeded = false; bool running = false; - if (ret && 0 == app_manager_is_running(ret, &running)) { - if (!running) { - MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", - pid, (ret ? ret : "NULL"), running); - mas_client_deinitialize(pid); - ret = NULL; - } + if (ret) { + do { + succeeded = (0 == app_manager_is_running(ret, &running)); + if (succeeded && !running) { + MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", + pid, (ret ? ret : "NULL"), running); + mas_client_deinitialize(pid); + ret = NULL; + } + if (!succeeded) usleep(10000); + } while(!succeeded && retry_num++ < 3); } -#endif return ret; } -- 2.7.4 From 8703e44b952a5d8f9053fac74983b067829d9502 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 12:03:24 +0900 Subject: [PATCH 04/16] Make sure uninstall completion event also restarts service Change-Id: I0349eeb25d3bf32c839c6eeb5ea566410b28e987 --- src/multi_assistant_service.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 6438333..9ed865e 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1476,6 +1476,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac pkgmgrinfo_pkginfo_h handle = NULL; static bool in_progress = false; bool should_exit = false; + bool pkginfo_found = true; if (!package || !type) return; @@ -1486,7 +1487,8 @@ static void _package_manager_event_cb(const char *type, const char *package, pac return; if (PACKAGE_MANAGER_EVENT_STATE_STARTED != event_state && - PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state) + PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state && + PACKAGE_MANAGER_EVENT_STATE_FAILED != event_state) return; bool user = false; @@ -1500,16 +1502,28 @@ static void _package_manager_event_cb(const char *type, const char *package, pac ret = pkgmgrinfo_pkginfo_get_usr_pkginfo (package, uid, &handle); if (ret != PMINFO_R_OK || NULL == handle) { LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ()); - return; + pkginfo_found = false; } } - if (user) { - /* Try to get in user packages */ - pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid); - } else { - /* Try to get in global packages */ - pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret); + if (pkginfo_found) { + if (user) { + /* Try to get in user packages */ + pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid); + } else { + /* Try to get in global packages */ + pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret); + } + } else { + /* Even if we failed acquiring the pkginfo, proceed if we're uninstalling + since at the time of uninstall completion, pkginfo would not exist */ + if (in_progress) { + if (PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL == event_type && + (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state || + PACKAGE_MANAGER_EVENT_STATE_FAILED == event_state)) { + ret = 1; + } + } } if (1 == ret) { if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) { @@ -1518,8 +1532,10 @@ static void _package_manager_event_cb(const char *type, const char *package, pac in_progress = true; deinit_plugin(); } - } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) { - LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type); + } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state || + PACKAGE_MANAGER_EVENT_STATE_FAILED == event_state) { + LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED/FAILED event : %d %d", + event_state, event_type); if (false == in_progress) { deinit_plugin(); } @@ -1528,7 +1544,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac } } - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + if (handle) pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (should_exit) { LOGI("Now restarting multi-assistant-service for reloading updated modules"); -- 2.7.4 From 8a540b3b1022845c79abc1dd336e24fece7f22e0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 27 May 2020 13:35:16 +0900 Subject: [PATCH 05/16] Bump version to 0.2.34 Change-Id: I63ad89fe501034375b402916d6ec1ae36fdcaa3c --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 4d64d60..db96b45 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 31eed78..f5ffa24 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.33 +Version: 0.2.34 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 63c1b48f41d2db9606e5a5c1d7e72c73156ef2db Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 28 May 2020 15:34:13 +0900 Subject: [PATCH 06/16] Bump version to 0.3.0 Change-Id: I0885fbe773417eac7446e218285f0e2dd040710c --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 7c451d8..6a9d5d7 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 68165fa..16df664 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.32 +Version: 0.3.0 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 5dcb093491a6775b36de86a4ece7f8b42fdd7373 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 4 Jun 2020 17:38:22 +0900 Subject: [PATCH 07/16] Prevent sending dbus messages to panel if panel is not enabled Change-Id: I85518b160461f93829cc0fe77a1a5af680659b02 --- src/service_main.cpp | 35 +++++++++++++++++++++++++---------- src/service_plugin.cpp | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index 656a91c..83f5f69 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -138,9 +138,13 @@ int CServiceMain::client_send_voice_key_status_change(pid_t pid, ma_voice_key_st int CServiceMain::client_send_asr_result(pid_t pid, int event, const char* asr_result) { MAS_LOGD("[Enter] pid(%d), event(%d), asr_result(%s)", pid, event, asr_result); - int ret = mServiceIpc.masc_ui_dbus_send_asr_result(pid, event, asr_result); - if (0 != ret){ - MAS_LOGE("[ERROR] Fail to send asr result, ret(%d)", ret); + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); + int ret = 0; + if (ui_panel_enabled) { + ret = mServiceIpc.masc_ui_dbus_send_asr_result(pid, event, asr_result); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to send asr result, ret(%d)", ret); + } } // if final event is , launch assistant app which is invoked with wakeup word. @@ -152,9 +156,13 @@ int CServiceMain::client_send_result(pid_t pid, const char* display_text, const char* utterance_text, const char* result_json) { MAS_LOGD("[Enter] pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json); - int ret = mServiceIpc.masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json); - if (0 != ret){ - MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret); + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); + int ret = 0; + if (ui_panel_enabled) { + mServiceIpc.masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret); + } } std::string pid_appid; @@ -170,9 +178,13 @@ int CServiceMain::client_send_result(pid_t pid, const char* display_text, int CServiceMain::client_send_recognition_result(pid_t pid, int result) { MAS_LOGD("[Enter] pid(%d), result(%d)", pid, result); - int ret = mServiceIpc.masc_ui_dbus_send_recognition_result(pid, result); - if (0 != ret){ - MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret); + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); + int ret = 0; + if (ui_panel_enabled) { + mServiceIpc.masc_ui_dbus_send_recognition_result(pid, result); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret); + } } std::string pid_appid; @@ -416,7 +428,10 @@ int CServiceMain::ui_client_change_assistant(const char* appid) } bool use_custom_ui = get_client_custom_ui_option_by_appid(appid); - mServiceIpc.masc_ui_dbus_enable_common_ui(!use_custom_ui); + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); + if (ui_panel_enabled) { + mServiceIpc.masc_ui_dbus_enable_common_ui(!use_custom_ui); + } set_current_client_by_appid(appid); pid_t pid = get_client_pid_by_appid(appid); diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 6cef985..2af558b 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -45,7 +45,7 @@ typedef struct { bool CServicePlugin::is_ui_panel_enabled() { /* By default we assume the ui panel is always enabled unless explicitly turned off */ - bool ret = true; + bool ret = false; if (mPluginSettings) { ret = mPluginSettings->ui_panel_enabled; } -- 2.7.4 From 2806f3f4473ee536e5609a8561a04adffcdb2b9f Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 4 Jun 2020 17:39:22 +0900 Subject: [PATCH 08/16] Remove unnecessary white space between function name and parenthesis Change-Id: I5ccf150157572b8dbc1b3c2ea96c81002a69124a --- src/service_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index 83f5f69..f40a2a8 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1272,7 +1272,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac user = true; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package, uid, &handle); if (ret != PMINFO_R_OK || NULL == handle) { - MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ()); + MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid()); pkginfo_found = false; } } -- 2.7.4 From 33412e4cef85993f661ce340d450f4a1540fbaa7 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 4 Jun 2020 17:39:44 +0900 Subject: [PATCH 09/16] Bump version to 0.3.2 Change-Id: I2cf047053df57fc2052be9c73d38e4afad4bd793 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 2e04448..378863b 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 7ba06df..8c201ec 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.1 +Version: 0.3.2 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 4c8d1a6431b61a35627de9e471d3b0bc400eac09 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 5 Jun 2020 11:26:54 +0900 Subject: [PATCH 10/16] Add missing ret value assignment Change-Id: I2adf76992cabce3cb987af655d2dd3cdf03561be --- src/service_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index f40a2a8..7830c3f 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -159,7 +159,7 @@ int CServiceMain::client_send_result(pid_t pid, const char* display_text, bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); int ret = 0; if (ui_panel_enabled) { - mServiceIpc.masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json); + ret = mServiceIpc.masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json); if (0 != ret){ MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret); } @@ -181,7 +181,7 @@ int CServiceMain::client_send_recognition_result(pid_t pid, int result) bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); int ret = 0; if (ui_panel_enabled) { - mServiceIpc.masc_ui_dbus_send_recognition_result(pid, result); + ret = mServiceIpc.masc_ui_dbus_send_recognition_result(pid, result); if (0 != ret){ MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret); } -- 2.7.4 From b60b5c2461cd93f4ef2244b652ec53902eed27ed Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 15 Jun 2020 10:38:50 +0900 Subject: [PATCH 11/16] Add utc for preference-manager-vconf Change-Id: Idac4acc21d911a0d08f1322eefb2ecadfd3f8b13 --- tests/utc/CMakeLists.txt | 1 + tests/utc/preference-manager-vconf/CMakeLists.txt | 59 ++++++++ .../test_preference_manager_vconf.cpp | 153 +++++++++++++++++++++ tests/utc/preference-manager-vconf/vconf_mock.cpp | 24 ++++ tests/utc/preference-manager-vconf/vconf_mock.h | 47 +++++++ 5 files changed, 284 insertions(+) create mode 100644 tests/utc/preference-manager-vconf/CMakeLists.txt create mode 100644 tests/utc/preference-manager-vconf/test_preference_manager_vconf.cpp create mode 100644 tests/utc/preference-manager-vconf/vconf_mock.cpp create mode 100644 tests/utc/preference-manager-vconf/vconf_mock.h diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt index 332b649..09b035f 100644 --- a/tests/utc/CMakeLists.txt +++ b/tests/utc/CMakeLists.txt @@ -4,3 +4,4 @@ ADD_SUBDIRECTORY(config) ADD_SUBDIRECTORY(client-manager) ADD_SUBDIRECTORY(audio-manager) ADD_SUBDIRECTORY(service-main) +ADD_SUBDIRECTORY(preference-manager-vconf) diff --git a/tests/utc/preference-manager-vconf/CMakeLists.txt b/tests/utc/preference-manager-vconf/CMakeLists.txt new file mode 100644 index 0000000..96c7491 --- /dev/null +++ b/tests/utc/preference-manager-vconf/CMakeLists.txt @@ -0,0 +1,59 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") + +SET(TEST_SOURCES + test_preference_manager_vconf.cpp + vconf_mock.cpp + ${CMAKE_SOURCE_DIR}/src/preference_manager_vconf.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + multi-assistant + dlog + libxml-2.0 +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FIND_PACKAGE(GTest REQUIRED) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) + +SET(TEST_PREFERENCE_MANAGER_VCONF test-preference-manager-vconf) +ADD_EXECUTABLE(${TEST_PREFERENCE_MANAGER_VCONF} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_PREFERENCE_MANAGER_VCONF} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +SET_TARGET_PROPERTIES(${TEST_PREFERENCE_MANAGER_VCONF} PROPERTIES + COMPILE_FLAGS "-fPIE" + #Never add any space for LINKFLAGS + LINK_FLAGS "-Wl,\ +--wrap=vconf_get_int,\ +--wrap=vconf_get_bool,\ +--wrap=vconf_get_str,\ +--wrap=vconf_notify_key_changed,\ +--wrap=vconf_ignore_key_changed,\ +--wrap=vconf_keynode_get_name") + +INSTALL(TARGETS ${TEST_PREFERENCE_MANAGER_VCONF} DESTINATION bin) + +ADD_TEST(NAME ${TEST_PREFERENCE_MANAGER_VCONF} COMMAND ${TEST_PREFERENCE_MANAGER_VCONF}) diff --git a/tests/utc/preference-manager-vconf/test_preference_manager_vconf.cpp b/tests/utc/preference-manager-vconf/test_preference_manager_vconf.cpp new file mode 100644 index 0000000..5ffe0c2 --- /dev/null +++ b/tests/utc/preference-manager-vconf/test_preference_manager_vconf.cpp @@ -0,0 +1,153 @@ +/* + * Copyright 2020 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "preference_manager_vconf.h" + +#include + +class DefaultFixture : public testing::Test +{ +public: + DefaultFixture() { + } + virtual ~DefaultFixture() { + } + void SetUp() override { + } + void TearDown() override { + } + + static void dummy_callback(std::string key, void* user_data) { + return; + } + CPreferenceManagerVconf preference_manager; +}; + +TEST_F(DefaultFixture, CanRegisterOneCallback) { + std::string arbitrary_key{"ArbitraryKey"}; + + bool ret = preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanRegisterTwoCallbacksForOneKey) { + std::string arbitrary_key{"ArbitraryKey"}; + preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + + bool ret = preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanRegisterTwoCallbacksForTwoDifferentKeys) { + std::string arbitrary_key_1{"ArbitraryKey1"}; + std::string arbitrary_key_2{"ArbitraryKey2"}; + preference_manager.register_changed_callback(arbitrary_key_1, dummy_callback, nullptr); + + bool ret = preference_manager.register_changed_callback(arbitrary_key_2, dummy_callback, nullptr); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanUnregisterOneCallback) { + std::string arbitrary_key{"ArbitraryKey"}; + preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key, dummy_callback); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanUnregisterTwoCallbacksForOneKey) { + std::string arbitrary_key{"ArbitraryKey"}; + preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key, dummy_callback, nullptr); + preference_manager.unregister_changed_callback(arbitrary_key, dummy_callback); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key, dummy_callback); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanUnregisterTwoCallbacksForTwoDifferentKeys) { + std::string arbitrary_key_1{"ArbitraryKey1"}; + std::string arbitrary_key_2{"ArbitraryKey2"}; + preference_manager.register_changed_callback(arbitrary_key_1, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key_2, dummy_callback, nullptr); + preference_manager.unregister_changed_callback(arbitrary_key_1, dummy_callback); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key_2, dummy_callback); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanUnregisterThreeCallbacksForThreeDifferentKeysForward) { + std::string arbitrary_key_1{"ArbitraryKey1"}; + std::string arbitrary_key_2{"ArbitraryKey2"}; + std::string arbitrary_key_3{"ArbitraryKey3"}; + preference_manager.register_changed_callback(arbitrary_key_1, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key_2, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key_3, dummy_callback, nullptr); + preference_manager.unregister_changed_callback(arbitrary_key_1, dummy_callback); + preference_manager.unregister_changed_callback(arbitrary_key_2, dummy_callback); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key_3, dummy_callback); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, CanUnregisterThreeCallbacksForThreeDifferentKeysBackward) { + std::string arbitrary_key_1{"ArbitraryKey1"}; + std::string arbitrary_key_2{"ArbitraryKey2"}; + std::string arbitrary_key_3{"ArbitraryKey3"}; + preference_manager.register_changed_callback(arbitrary_key_1, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key_2, dummy_callback, nullptr); + preference_manager.register_changed_callback(arbitrary_key_3, dummy_callback, nullptr); + preference_manager.unregister_changed_callback(arbitrary_key_3, dummy_callback); + preference_manager.unregister_changed_callback(arbitrary_key_2, dummy_callback); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key_1, dummy_callback); + + ASSERT_EQ(ret, true); +} + +TEST_F(DefaultFixture, UnregisterFailsOnKeyNotExists) { + std::string arbitrary_key{"ArbitraryKey"}; + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key, dummy_callback); + + ASSERT_EQ(ret, false); +} + +TEST_F(DefaultFixture, UnregisterFailurePreservesExistingEntry) { + std::string arbitrary_key_1{"ArbitraryKey1"}; + std::string arbitrary_key_2{"ArbitraryKey2"}; + preference_manager.register_changed_callback(arbitrary_key_1, dummy_callback, nullptr); + preference_manager.unregister_changed_callback(arbitrary_key_2, dummy_callback); + + bool ret = preference_manager.unregister_changed_callback(arbitrary_key_1, dummy_callback); + + ASSERT_EQ(ret, true); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/tests/utc/preference-manager-vconf/vconf_mock.cpp b/tests/utc/preference-manager-vconf/vconf_mock.cpp new file mode 100644 index 0000000..edaf16e --- /dev/null +++ b/tests/utc/preference-manager-vconf/vconf_mock.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "vconf_mock.h" + +int __wrap_vconf_get_int(const char *in_key, int *intval) { return 0; } +int __wrap_vconf_get_bool(const char *in_key, int *boolval) { return 0; } +char *__wrap_vconf_get_str(const char *in_key) { return nullptr; } +int __wrap_vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, void *user_data) { return 0; } +int __wrap_vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb) { return 0; } +char *__wrap_vconf_keynode_get_name(keynode_t *keynode) { return nullptr; } diff --git a/tests/utc/preference-manager-vconf/vconf_mock.h b/tests/utc/preference-manager-vconf/vconf_mock.h new file mode 100644 index 0000000..23d3750 --- /dev/null +++ b/tests/utc/preference-manager-vconf/vconf_mock.h @@ -0,0 +1,47 @@ +/* + * Copyright 2020 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 VCONF_MOCK_H +#define VCONF_MOCK_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _keynode_t { + char *keyname; /**< Keyname for keynode */ + int type; /**< Keynode type */ + union { + int i; /**< Integer type */ + int b; /**< Bool type */ + double d; /**< Double type */ + char *s; /**< String type */ + } value; /**< Value for keynode */ +} keynode_t; +typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data); + +int __wrap_vconf_get_int(const char *in_key, int *intval); +int __wrap_vconf_get_bool(const char *in_key, int *boolval); +char *__wrap_vconf_get_str(const char *in_key); +int __wrap_vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, void *user_data); +int __wrap_vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb); +char *__wrap_vconf_keynode_get_name(keynode_t *keynode); + +#ifdef __cplusplus +} +#endif + +#endif -- 2.7.4 From e382a2d87650c192c378779a326144ebf4a28dc1 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 15 Jun 2020 11:49:08 +0900 Subject: [PATCH 12/16] Fix utc failure : test-preference-manager-vconf 1. Make unregister_changed_callback to return true only when a certain item was removed from list. 2. Fix crash caused by removing an element inside a range-based for loop. (Now using remove_if instead) Change-Id: I9c676b52c2e63c4f69db35169a4bf967e1d1bf64 --- src/preference_manager_vconf.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/preference_manager_vconf.cpp b/src/preference_manager_vconf.cpp index 985ae38..551d5da 100644 --- a/src/preference_manager_vconf.cpp +++ b/src/preference_manager_vconf.cpp @@ -127,22 +127,26 @@ bool CPreferenceManagerVconf::register_changed_callback( bool CPreferenceManagerVconf::unregister_changed_callback(const std::string& key, preference_changed_cb callback) { + bool removed = false; std::map>::iterator map_iter = mCallbackEntries.find(key); if (map_iter != mCallbackEntries.end()) { - bool found = false; - for (const auto& entry : map_iter->second) { - if (callback == std::get<0>(entry)) { - if (!found) { - map_iter->second.remove(entry); - found = true; + map_iter->second.remove_if( + [&](const CallbackEntry& entry) { + bool found = false; + if (callback == std::get<0>(entry)) { + /* Unregister only one entry at a time */ + if (!removed) { + found = true; + } } - } - } + if (found) removed = true; + return found; + }); if (map_iter->second.empty()) { vconf_ignore_key_changed(key.c_str(), vconf_key_changed); } } - return true; + return removed; } -- 2.7.4 From efb490080309c118c4d48eab95e8fb80b5ac6f3e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 15 Jun 2020 11:53:18 +0900 Subject: [PATCH 13/16] Bump version to 0.3.3 Change-Id: Idf3fcc0402c1f5979071c8859c8c842fc2b450f6 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 378863b..2a18a99 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 8c201ec..10c9ac5 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.2 +Version: 0.3.3 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 9549b5c5b81aa3be186cac1e7caabd05e34c5504 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 17 Jul 2020 14:30:26 +0900 Subject: [PATCH 14/16] Use async version of aul_launch_app for avoiding deadlock Change-Id: I484ced8492df92262ee34e19b687ae62d4cba76f --- src/multi_assistant_service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 9ed865e..3fc3b00 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1184,9 +1184,9 @@ int mas_bring_client_to_foreground(const char* appid) return -1; } - int result = aul_launch_app(appid, b); + int result = aul_launch_app_async(appid, b); if (result < AUL_R_OK) { - MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", + MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]", appid, b, result, get_error_message(result)); } -- 2.7.4 From 39ee9688098e5e7f79fe5d510373fed1c6446152 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 17 Jul 2020 11:42:04 +0900 Subject: [PATCH 15/16] Bump version to 0.2.35 Change-Id: Ib8b1ca66b5e49ef6266973cb960092c7839473a3 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index db96b45..c012fe7 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index f5ffa24..5288e81 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.34 +Version: 0.2.35 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From e667ff3d7f76ec4daf1c2f8cdd7defe789ae9647 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 22 Jul 2020 16:49:01 +0900 Subject: [PATCH 16/16] Bump version to 0.3.4 Change-Id: I07a09e3abf3283bd5e737bbb7682b689c6a6d204 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 2a18a99..83153e1 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 10c9ac5..4781812 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.3 +Version: 0.3.4 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4