From 68f452ad396d89e55a647e0025fd7aba0aeecf1e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 2 Apr 2020 00:03:59 +0900 Subject: [PATCH 01/16] Extract aul dependency from service_main.cpp Change-Id: Ifd796751933776c0153e8c78d345b94542ac37da --- inc/application_manager.h | 5 + inc/application_manager_aul.h | 6 +- inc/service_common.h | 2 + inc/service_main.h | 2 - src/application_manager_aul.cpp | 76 +++++++- src/service_main.cpp | 218 +++++++++-------------- tests/utc/client-manager/test_client_manager.cpp | 4 + 7 files changed, 176 insertions(+), 137 deletions(-) diff --git a/inc/application_manager.h b/inc/application_manager.h index f6733fc..08b2586 100644 --- a/inc/application_manager.h +++ b/inc/application_manager.h @@ -18,6 +18,7 @@ #ifndef __APPLICATION_MANAGER_H__ #define __APPLICATION_MANAGER_H__ +#include #include #ifdef __cplusplus @@ -27,6 +28,10 @@ extern "C" { class IApplicationManager { public: virtual bool is_application_running(int pid) = 0; + virtual bool is_application_running(const std::string& appid) = 0; + virtual bool bring_app_to_foreground(const std::string& appid) = 0; + virtual bool launch_app_async(const std::string& appid, bool background) = 0; + virtual boost::optional get_appid_by_pid(int pid) = 0; }; #ifdef __cplusplus diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index 2c47dc2..b0b3dd3 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -20,8 +20,6 @@ #include "application_manager.h" -#include - #ifdef __cplusplus extern "C" { #endif @@ -29,6 +27,10 @@ extern "C" { class CApplicationManagerAul : public IApplicationManager { public: virtual bool is_application_running(int pid) override; + virtual bool is_application_running(const std::string& appid) override; + virtual bool bring_app_to_foreground(const std::string& appid) override; + virtual bool launch_app_async(const std::string& appid, bool background) override; + virtual boost::optional get_appid_by_pid(int pid) override; }; #ifdef __cplusplus diff --git a/inc/service_common.h b/inc/service_common.h index ecef87d..747b57a 100644 --- a/inc/service_common.h +++ b/inc/service_common.h @@ -125,6 +125,8 @@ typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e #define MAX_SUPPORTED_LANGUAGES_NUM 255 #define MAX_SUPPORTED_LANGUAGE_LEN 16 +#define MAX_APPID_LEN 255 + typedef enum { VOICE_KEY_SUPPORT_MODE_NONE, VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK, diff --git a/inc/service_main.h b/inc/service_main.h index 4bfaddd..4a6ddfa 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -37,8 +37,6 @@ extern "C" { #endif -#define MAX_APPID_LEN 255 - typedef enum { CLIENT_LAUNCH_MODE_ACTIVATION, CLIENT_LAUNCH_MODE_PRELAUNCH, diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 2553c93..5cf8855 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -18,6 +18,7 @@ #include "service_common.h" #include +#include bool CApplicationManagerAul::is_application_running(int pid) { @@ -27,4 +28,77 @@ bool CApplicationManagerAul::is_application_running(int pid) return false; } return true; -} \ No newline at end of file +} + +bool CApplicationManagerAul::is_application_running(const std::string& appid) +{ + return (!!aul_app_is_running(appid.c_str())); +} + +bool CApplicationManagerAul::bring_app_to_foreground(const std::string& appid) +{ + bool ret = true; + + /* Bring MA client to foreground - is there a better way other than launching? */ + bundle *b = NULL; + b = bundle_create(); + if (NULL == b) { + MAS_LOGE("Failed creating bundle for aul operation"); + return -1; + } + + int result = aul_launch_app(appid.c_str(), b); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + ret = false; + } + + if (b) bundle_free(b); + b = NULL; + + return ret; +} + +bool CApplicationManagerAul::launch_app_async(const std::string& appid, bool background) +{ + bool ret = true; + + bundle *b = NULL; + b = bundle_create(); + if (NULL == b) { + MAS_LOGE("Failed creating bundle for aul operation"); + return false; + } + + int result = aul_svc_set_background_launch(b, background); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + } + + result = aul_launch_app_async(appid.c_str(), b); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + ret = false; + } + + if (b) bundle_free(b); + b = NULL; + + return ret; +} + +boost::optional CApplicationManagerAul::get_appid_by_pid(int pid) +{ + boost::optional ret; + + char appid[MAX_APPID_LEN] = {'\0', }; + if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) { + appid[MAX_APPID_LEN - 1] = '\0'; + ret = std::string{appid}; + } + + return ret; +} diff --git a/src/service_main.cpp b/src/service_main.cpp index cad2c4a..5e660f9 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include #include @@ -160,13 +158,12 @@ int CServiceMain::mas_client_send_result(int pid, const char* display_text, MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret); } - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_recognition_result(pid_appid, MA_RECOGNITION_RESULT_EVENT_SUCCESS); + mServicePlugin.update_recognition_result(pid_appid.c_str(), MA_RECOGNITION_RESULT_EVENT_SUCCESS); return ret; } @@ -179,13 +176,12 @@ int CServiceMain::mas_client_send_recognition_result(int pid, int result) MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret); } - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_recognition_result(pid_appid, result); + mServicePlugin.update_recognition_result(pid_appid.c_str(), result); return ret; } @@ -229,52 +225,48 @@ int CServiceMain::mas_client_stop_streaming_audio_data(int pid, int type) int CServiceMain::mas_client_update_voice_feedback_state(int pid, int state) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_voice_feedback_state(pid_appid, state); + mServicePlugin.update_voice_feedback_state(pid_appid.c_str(), state); return 0; } int CServiceMain::mas_client_set_assistant_specific_command(int pid, const char *command) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_assistant_specific_command(pid_appid, command); + mServicePlugin.set_assistant_specific_command(pid_appid.c_str(), command); return 0; } int CServiceMain::mas_client_set_background_volume(int pid, double ratio) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_background_volume(pid_appid, ratio); + mServicePlugin.set_background_volume(pid_appid.c_str(), ratio); return 0; } int CServiceMain::mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char* appid) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used) { - if (pid_appid && strncmp(pid_appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + if (0 == pid_appid.compare(mClientInfo[loop].appid)) { mClientInfo[loop].preprocessing_allow_mode = mode; if (appid) { strncpy(mClientInfo[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN); @@ -293,13 +285,12 @@ int CServiceMain::mas_client_set_preprocessing_allow_mode(int pid, ma_preprocess int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - if (!is_current_preprocessing_assistant(pid_appid)) return -1; + if (!is_current_preprocessing_assistant(pid_appid.c_str())) return -1; const char *current_maclient_appid = NULL; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { @@ -307,7 +298,7 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) } if (result) { - MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid); + MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid.c_str()); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED); } else { MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid); @@ -325,49 +316,44 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) int CServiceMain::mas_client_set_wake_word_audio_require_flag(int pid, bool require) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_wake_word_audio_require_flag(pid_appid, require); + mServicePlugin.set_wake_word_audio_require_flag(pid_appid.c_str(), require); return 0; } int CServiceMain::mas_client_set_assistant_language(int pid, const char* language) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf)); - if (AUL_R_OK == ret) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_assistant_language(pid_appid, language); + mServicePlugin.set_assistant_language(pid_appid.c_str(), language); return 0; } int CServiceMain::mas_client_add_wake_word(int pid, const char* wake_word, const char* language) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf)); - if (AUL_R_OK == ret) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used && - 0 == strncmp(buf, mClientInfo[loop].appid, MAX_APPID_LEN)) { - ret = mServiceConfig.add_custom_wake_word(wake_word, language, + 0 == pid_appid.compare(mClientInfo[loop].appid)) { + int ret = mServiceConfig.add_custom_wake_word(wake_word, language, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); if (0 == ret) { - mServiceConfig.save_custom_wake_words(pid_appid, + mServiceConfig.save_custom_wake_words(pid_appid.c_str(), mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); } else { @@ -377,35 +363,33 @@ int CServiceMain::mas_client_add_wake_word(int pid, const char* wake_word, const } } - mServicePlugin.add_assistant_wakeup_word(pid_appid, wake_word, language); + mServicePlugin.add_assistant_wakeup_word(pid_appid.c_str(), wake_word, language); return 0; } int CServiceMain::mas_client_remove_wake_word(int pid, const char* wake_word, const char* language) { - const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0', }; - int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf)); - if (AUL_R_OK == ret) { - buf[MAX_APPID_LEN - 1] = '\0'; - pid_appid = buf; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used && - 0 == strncmp(buf, mClientInfo[loop].appid, MAX_APPID_LEN)) { - ret = mServiceConfig.remove_custom_wake_word(wake_word, language, + 0 == pid_appid.compare(mClientInfo[loop].appid)) { + int ret = mServiceConfig.remove_custom_wake_word(wake_word, language, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); if (0 == ret) { - mServiceConfig.save_custom_wake_words(pid_appid, + mServiceConfig.save_custom_wake_words(pid_appid.c_str(), mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); } } } - mServicePlugin.remove_assistant_wakeup_word(pid_appid, wake_word, language); + mServicePlugin.remove_assistant_wakeup_word(pid_appid.c_str(), wake_word, language); return 0; } @@ -720,10 +704,8 @@ int CServiceMain::mas_get_client_pid_by_appid(const char *appid) ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } - int status = aul_app_get_status_bypid(ret); - if (-1 != ret && 0 > status) { - MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", - (appid ? appid : "NULL"), ret, status); + if (-1 != ret && !mApplicationManager.is_application_running(ret)) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid, ret); on_deinitialize(ret); ret = -1; } @@ -879,36 +861,22 @@ int CServiceMain::mas_set_current_client_by_appid(const char *appid) int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode) { + int result = 0; + if (NULL == appid || 0 == strlen(appid)) { MAS_LOGE("appid invalid, failed launching MA Client"); return -1; } if (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode) { - if (1 == aul_app_is_running(appid)) { + if (mApplicationManager.is_application_running(appid)) { MAS_LOGE("appid %s is already running, no need for a prelaunch", appid); return -1; } - } - - bundle *b = NULL; - b = bundle_create(); - if (NULL == b) { - MAS_LOGE("Failed creating bundle for aul operation"); - return -1; - } - int result = aul_svc_set_background_launch(b, - (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode ? TRUE : FALSE)); - if (result < AUL_R_OK) { - MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]", - appid, b, result, get_error_message(result)); - } - - result = aul_launch_app_async(appid, b); - if (result < AUL_R_OK) { - MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]", - appid, b, result, get_error_message(result)); + result = mApplicationManager.launch_app_async(appid, true); + } else { + result = mApplicationManager.launch_app_async(appid, false); } if (CLIENT_LAUNCH_MODE_ACTIVATION == launch_mode) { @@ -925,37 +893,23 @@ int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MO MAS_LOGD("mWakeupClientAppId : %s, %d", mWakeupClientAppId.c_str(), found); } - if (b) bundle_free(b); - b = NULL; - return result; } int CServiceMain::mas_bring_client_to_foreground(const char* appid) { - /* Bring MA client to foreground - is there a better way other than launching? */ + int ret = 0; + if (NULL == appid || 0 == strlen(appid)) { MAS_LOGE("appid invalid, failed launching MA Client"); return -1; } - bundle *b = NULL; - b = bundle_create(); - if (NULL == b) { - MAS_LOGE("Failed creating bundle for aul operation"); - return -1; - } - - int result = aul_launch_app(appid, b); - if (result < AUL_R_OK) { - MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", - appid, b, result, get_error_message(result)); + if (!mApplicationManager.bring_app_to_foreground(appid)) { + ret = -1; } - if (b) bundle_free(b); - b = NULL; - - return result; + return ret; } int CServiceMain::mas_launch_client_by_wakeup_word(const char *wakeup_word) @@ -972,7 +926,7 @@ int CServiceMain::mas_prelaunch_default_assistant() if (prelaunch_mode && *prelaunch_mode) { const char *default_assistant = NULL; if (0 == mServicePlugin.get_default_assistant(&default_assistant)) { - if (0 == aul_app_is_running(default_assistant)) { + if (!(mApplicationManager.is_application_running(default_assistant))) { MAS_LOGD("prelaunching default_assistant_appid : %s", default_assistant); mas_launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH); } @@ -1382,19 +1336,19 @@ void CServiceMain::app_terminate(void *data) int CServiceMain::on_initialize(int pid) { MAS_LOGD("[Enter] pid(%d)", pid); - char appid[MAX_APPID_LEN] = {'\0', }; - if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) { - appid[MAX_APPID_LEN - 1] = '\0'; - - MAS_LOGD("appid for pid %d is : %s", pid, (appid ? appid : "Unknown")); + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; + MAS_LOGD("appid for pid %d is : %s", pid, pid_appid.c_str()); /* Remove existing client that has same appid, if there's any */ - mClientManager.destroy_client_by_appid(appid); + mClientManager.destroy_client_by_appid(pid_appid.c_str()); /* And remove a client that has same pid also */ mClientManager.destroy_client_by_pid(pid); - mClientManager.create_client(pid, appid); + mClientManager.create_client(pid, pid_appid.c_str()); const char *current_maclient_appid = NULL; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { @@ -1405,16 +1359,16 @@ int CServiceMain::on_initialize(int pid) { if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) { mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus); } - if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) { + if (current_maclient_appid && 0 == pid_appid.compare(current_maclient_appid)) { MAS_LOGD("MA client with current maclient appid connected!"); - if (0 == mWakeupClientAppId.compare(appid)) { + if (0 == mWakeupClientAppId.compare(pid_appid)) { mWakeupClientAppId.clear(); mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { MAS_LOGE("[ERROR] mWakeupClientAppId and appid differ : %s %s", - mWakeupClientAppId.c_str(), appid); + mWakeupClientAppId.c_str(), pid_appid.c_str()); } } else { MAS_LOGD("MA client connected, but its appid does not match with current maclient"); diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp index e77ded9..ef1357f 100644 --- a/tests/utc/client-manager/test_client_manager.cpp +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -27,6 +27,10 @@ public: virtual ~CDummyApplicationManager() {}; bool is_application_running(int pid) { return true; } + bool is_application_running(const std::string& appid) { return true; } + bool bring_app_to_foreground(const std::string& appid) { return true; } + bool launch_app_async(const std::string& appid, bool background) { return true; } + boost::optional get_appid_by_pid(int pid) { return boost::optional{}; } }; class StorageWithNoClient : public testing::Test -- 2.7.4 From 5451033ad77a8234247a8560973a3fb001a38712 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 2 Apr 2020 22:58:29 +0900 Subject: [PATCH 02/16] Remove unnecessary variable declaration Change-Id: Idc88d765c482f98e25dee988d7e58245cbda502c --- src/service_main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index 5e660f9..270f14d 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1092,8 +1092,6 @@ int CServiceMain::mas_set_current_service_state(ma_service_state_e state) { mCurrentServiceState = state; - ma_client_s *data = NULL; - int count = mClientManager.get_client_num(); int i; -- 2.7.4 From 5ec3e8802bd83acce735ad378ac2085f6b99e519 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 2 Apr 2020 22:55:41 +0900 Subject: [PATCH 03/16] Add sample unit test for CServiceMain and fix related errors Change-Id: I280242fb68e90473688abba06a5b333f62225b61 --- CMakeLists.txt | 2 +- inc/application_manager_aul.h | 3 + inc/service_config.h | 18 +++- src/application_manager_aul.cpp | 8 ++ src/service_config.cpp | 14 --- src/service_main.cpp | 11 ++- tests/utc/CMakeLists.txt | 1 + tests/utc/service-main/CMakeLists.txt | 59 ++++++++++++ tests/utc/service-main/test_service_main.cpp | 135 +++++++++++++++++++++++++++ 9 files changed, 231 insertions(+), 20 deletions(-) create mode 100644 tests/utc/service-main/CMakeLists.txt create mode 100644 tests/utc/service-main/test_service_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 61c3363..5bd511e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) SET(SRCS - src/main.cpp src/service_config.cpp src/application_manager_aul.cpp src/preference_manager_vconf.cpp @@ -76,6 +75,7 @@ SET(SRCS src/service_plugin.cpp src/service_ipc_dbus.cpp src/service_ipc_dbus_dispatcher.cpp + src/main.cpp ) ADD_EXECUTABLE(${BINNAME} ${SRCS}) diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index b0b3dd3..e4edbba 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -26,6 +26,9 @@ extern "C" { class CApplicationManagerAul : public IApplicationManager { public: + CApplicationManagerAul(); + ~CApplicationManagerAul(); + virtual bool is_application_running(int pid) override; virtual bool is_application_running(const std::string& appid) override; virtual bool bring_app_to_foreground(const std::string& appid) override; diff --git a/inc/service_config.h b/inc/service_config.h index 18fccbc..d77a4a0 100644 --- a/inc/service_config.h +++ b/inc/service_config.h @@ -59,7 +59,23 @@ extern "C" #define VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK "tap_to_talk" #define VOICE_KEY_SUPPORT_MODE_STRING_ALL "all" -typedef struct { +typedef struct ma_assistant_info_s { + ma_assistant_info_s() : + app_id{nullptr}, + name{nullptr}, + icon_path{nullptr}, + wakeup_list{0x00, }, + wakeup_language{0x00, }, + cnt_wakeup{0}, + supported_lang{0x00, }, + cnt_lang{0}, + wakeup_engine{nullptr}, + custom_ui_option{false}, + /* TODO: Define these two default values somewhere else */ + voice_key_support_mode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK}, + voice_key_tap_duration{0.0f} /* Meaning not set */ + {} + const char* app_id; const char* name; const char* icon_path; diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 5cf8855..b3863ad 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -20,6 +20,14 @@ #include #include +CApplicationManagerAul::CApplicationManagerAul() +{ +} + +CApplicationManagerAul::~CApplicationManagerAul() +{ +} + bool CApplicationManagerAul::is_application_running(int pid) { int status = aul_app_get_status_bypid(pid); diff --git a/src/service_config.cpp b/src/service_config.cpp index 44c4eaa..97b90ee 100644 --- a/src/service_config.cpp +++ b/src/service_config.cpp @@ -71,20 +71,6 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba /* alloc assistant info */ ma_assistant_info_s temp; - temp.app_id = NULL; - temp.name = NULL; - temp.icon_path = NULL; - memset(temp.wakeup_list, 0x00, sizeof(temp.wakeup_list)); - memset(temp.wakeup_language, 0x00, sizeof(temp.wakeup_language)); - temp.cnt_wakeup = 0; - memset(temp.supported_lang, 0x00, sizeof(temp.supported_lang)); - temp.cnt_lang = 0; - temp.wakeup_engine = NULL; - temp.custom_ui_option = false; - /* TODO: Define these two default values somewhere else */ - temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK; - temp.voice_key_tap_duration = 0.0f; /* Meaning not set */ - while (cur != NULL) { if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_LANGUAGE_SET)) { xmlNodePtr child_node = cur->xmlChildrenNode; diff --git a/src/service_main.cpp b/src/service_main.cpp index 270f14d..86b4001 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -586,17 +586,19 @@ int CServiceMain::initialize_service_plugin(void) if (0 == mServiceConfig.get_assistant_info(mas_assistant_info_cb, this)) { for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { int inner_loop; - if (mClientInfo[loop].used && + if (mClientInfo[loop].used && mClientInfo[loop].appid && 0 < strlen(mClientInfo[loop].appid)) { mServiceConfig.load_custom_wake_words(mClientInfo[loop].appid, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); - if (0 < strlen(mClientInfo[loop].wakeup_engine)) { + if (mClientInfo[loop].wakeup_engine && + 0 < strlen(mClientInfo[loop].wakeup_engine)) { mServicePlugin.set_assistant_wakeup_engine( mClientInfo[loop].appid, mClientInfo[loop].wakeup_engine); } for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { - if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { + if (mClientInfo[loop].wakeup_word[inner_loop] && + 0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { MAS_LOGD("Registering wakeup word %s for app %s", mClientInfo[loop].wakeup_word[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_wakeup_word( @@ -608,7 +610,8 @@ int CServiceMain::initialize_service_plugin(void) } } for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) { - if (0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { + if (mClientInfo[loop].supported_language[inner_loop] && + 0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { MAS_LOGD("Adding language %s for app %s", mClientInfo[loop].supported_language[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_language( diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt index 887d8a3..332b649 100644 --- a/tests/utc/CMakeLists.txt +++ b/tests/utc/CMakeLists.txt @@ -3,3 +3,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_SUBDIRECTORY(config) ADD_SUBDIRECTORY(client-manager) ADD_SUBDIRECTORY(audio-manager) +ADD_SUBDIRECTORY(service-main) diff --git a/tests/utc/service-main/CMakeLists.txt b/tests/utc/service-main/CMakeLists.txt new file mode 100644 index 0000000..69a4d83 --- /dev/null +++ b/tests/utc/service-main/CMakeLists.txt @@ -0,0 +1,59 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/inc/ + ) + +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_service_main.cpp + ${CMAKE_SOURCE_DIR}/src/service_main.cpp + ${CMAKE_SOURCE_DIR}/src/service_ipc_dbus.cpp + ${CMAKE_SOURCE_DIR}/src/service_ipc_dbus_dispatcher.cpp + ${CMAKE_SOURCE_DIR}/src/service_plugin.cpp + ${CMAKE_SOURCE_DIR}/src/service_config.cpp + ${CMAKE_SOURCE_DIR}/src/client_manager.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + capi-appfw-package-manager + capi-appfw-service-application + capi-message-port + multi-assistant + dlog + libxml-2.0 + ecore + pkgmgr-info +) + +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_SERVICE_MAIN test-service-main) +ADD_EXECUTABLE(${TEST_SERVICE_MAIN} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_SERVICE_MAIN} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TEST_SERVICE_MAIN} DESTINATION bin) + +ADD_TEST(NAME ${TEST_SERVICE_MAIN} COMMAND ${TEST_SERVICE_MAIN}) diff --git a/tests/utc/service-main/test_service_main.cpp b/tests/utc/service-main/test_service_main.cpp new file mode 100644 index 0000000..1ff69ef --- /dev/null +++ b/tests/utc/service-main/test_service_main.cpp @@ -0,0 +1,135 @@ +/* + * Copyright 2018 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 "service_main.h" + +#include +#include +#include + +class CDummyApplicationManager : public IApplicationManager +{ +public: + CDummyApplicationManager() {}; + ~CDummyApplicationManager() {}; + + bool is_application_running(int pid) override { return false; } + bool is_application_running(const std::string& appid) override { return false; } + bool bring_app_to_foreground(const std::string& appid) override + { + brought_to_foreground_appid = appid; + return true; + } + bool launch_app_async(const std::string& appid, bool background) override + { + launched_appid = appid; + launched_option_background = background; + return true; + } + boost::optional get_appid_by_pid(int pid) override { return boost::optional{}; } +public: + boost::optional launched_appid; + boost::optional launched_option_background; + boost::optional brought_to_foreground_appid;; +}; + +class CDummyPreferenceManager : public IPreferenceManager +{ +public: + CDummyPreferenceManager() {} + ~CDummyPreferenceManager() {} + + boost::optional get_string(const std::string& key) override + { + boost::optional ret; + const auto& iter = key_value_string.find(key); + if (iter != key_value_string.end()) { + ret = iter->second; + } + return ret; + } + boost::optional get_int(const std::string& key) override + { + boost::optional ret; + const auto& iter = key_value_int.find(key); + if (iter != key_value_int.end()) { + ret = iter->second; + } + return ret; + } + boost::optional get_bool(const std::string& key) override + { + boost::optional ret; + const auto& iter = key_value_bool.find(key); + if (iter != key_value_bool.end()) { + ret = iter->second; + } + return ret; + } + + bool register_changed_callback( + const std::string& key, preference_changed_cb calback, void* user_data) override { return true; } + bool unregister_changed_callback( + const std::string& key, preference_changed_cb callback) override { return true; } +public: + std::map key_value_string; + std::map key_value_int; + std::map key_value_bool; +}; + +class DefaultFixure : public testing::Test +{ +public: + DefaultFixure() { + } + virtual ~DefaultFixure() { + } + void SetUp() override { + } + void TearDown() override { + } + CDummyApplicationManager application_manager; + CDummyPreferenceManager preference_manager; + + CServiceMain service{application_manager, preference_manager}; +}; + +TEST_F(DefaultFixure, BringsDefaultAssistantToFrontOnAssistantActivatedPreprocessingStateEvent) { + std::string assistant_appid{"Arbitrary Assistant"}; + ma_assistant_info_s info; + info.app_id = assistant_appid.c_str(); + service.add_assistant_info(&info); + service.mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); + + bool brought = false; + if (application_manager.brought_to_foreground_appid) { + brought = true; + } + + ASSERT_TRUE(brought); +} + +int main(int argc, char** argv) { + const char* seconds = getenv("TEST_SLEEP_SECONDS"); + if (seconds) { + sleep(atoi(seconds)); + } + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} -- 2.7.4 From bdf4022693ee0c5ec2e0b2d4bcb50a1806a7faf2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 3 Apr 2020 15:08:40 +0900 Subject: [PATCH 04/16] Fix build break caused by incorrect type inference Change-Id: Idc32c9428d0592a60b01a0a156fa924d6d64c23e --- .../dependency-default/src/dependency_default_button.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp index f3684a8..f11ee97 100644 --- a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp +++ b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp @@ -59,7 +59,7 @@ static Eina_Bool _key_up_cb(void* data, int type, void* event) chrono::time_point current_time_point; current_time_point = chrono::system_clock::now(); auto diff = current_time_point - g_last_key_pressed; - auto milliseconds = chrono::duration_cast(diff).count(); + long long int milliseconds = chrono::duration_cast(diff).count(); LOGD("milliseconds : %lld", milliseconds); mas_plugin_event_e event; if (milliseconds < g_voice_key_tap_duration) { @@ -160,4 +160,4 @@ void dependency_default_button_set_voice_key_tap_duration(float duration) void dependency_default_button_unset_voice_key_tap_duration(void) { g_voice_key_tap_duration = DEFAULT_KEY_TAP_DURATION; -} \ No newline at end of file +} -- 2.7.4 From 5d331841e67319247450ea02bcdb1d017fade212 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 3 Apr 2020 15:51:55 +0900 Subject: [PATCH 05/16] Fix defects detected by static analysis tool Fixes the problem that local variable names are same with parameter names. Change-Id: Id60bc907d2e8142f739c01502d7202f4c6435cdd --- .../dependency-default/src/dependency_default_button.cpp | 8 ++++---- plugins/wakeup-manager/src/assistant_config_manager.cpp | 4 ++-- src/service_main.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp index f11ee97..140ac41 100644 --- a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp +++ b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp @@ -61,14 +61,14 @@ static Eina_Bool _key_up_cb(void* data, int type, void* event) auto diff = current_time_point - g_last_key_pressed; long long int milliseconds = chrono::duration_cast(diff).count(); LOGD("milliseconds : %lld", milliseconds); - mas_plugin_event_e event; + mas_plugin_event_e plugin_event; if (milliseconds < g_voice_key_tap_duration) { - event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_TAP; + plugin_event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_TAP; } else { - event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH; + plugin_event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH; } if (g_proxy_interface.process_event) { - g_proxy_interface.process_event(event, NULL, 0); + g_proxy_interface.process_event(plugin_event, NULL, 0); } } } diff --git a/plugins/wakeup-manager/src/assistant_config_manager.cpp b/plugins/wakeup-manager/src/assistant_config_manager.cpp index e15b411..bdc7461 100644 --- a/plugins/wakeup-manager/src/assistant_config_manager.cpp +++ b/plugins/wakeup-manager/src/assistant_config_manager.cpp @@ -64,10 +64,10 @@ void CAssistantConfigManager::foreach_assistant_language(foreach_assistant_langu closure.user_data = user_data; preference_foreach_item( - [](const char *key, void *user_data) { + [](const char *key, void *data) { string prefix = string{LANGUAGE_PREFIX}; foreach_assistant_language_cb_closure* closure = - static_cast(user_data); + static_cast(data); if (key && strlen(key) > prefix.length() && 0 == prefix.compare(0, prefix.length(), key, prefix.length())) { char* value = nullptr; diff --git a/src/service_main.cpp b/src/service_main.cpp index 86b4001..b023aa4 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -306,9 +306,9 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) } if (current_maclient_appid) { - int pid = mClientManager.find_client_pid_by_appid( + int pid_by_appid = mClientManager.find_client_pid_by_appid( std::string{current_maclient_appid}); - mServiceIpc.send_preprocessing_result(pid, result); + mServiceIpc.send_preprocessing_result(pid_by_appid, result); } return 0; -- 2.7.4 From 48c2b2f02ed7e308605c95773b0b25a0782cbfb2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 6 Apr 2020 18:40:12 +0900 Subject: [PATCH 06/16] Fix incorrect year information in license boilerplate Change-Id: Ieb79b85b5a51f8382787dabb84280fbd5af3ac53 --- inc/application_manager.h | 2 +- inc/application_manager_aul.h | 2 +- inc/client_manager.h | 2 +- inc/preference_manager.h | 2 +- inc/preference_manager_vconf.h | 2 +- inc/service_config.h | 2 +- inc/service_ipc_dbus.h | 2 +- inc/service_ipc_dbus_dispatcher.h | 2 +- inc/service_main.h | 2 +- inc/service_plugin.h | 2 +- inc/service_plugin_interface.h | 2 +- plugins/wakeup-manager/inc/wakeup_policy_external.h | 2 +- src/application_manager_aul.cpp | 2 +- src/client_manager.cpp | 2 +- src/preference_manager_vconf.cpp | 2 +- src/service_config.cpp | 2 +- src/service_ipc_dbus.cpp | 2 +- src/service_ipc_dbus_dispatcher.cpp | 2 +- src/service_main.cpp | 2 +- src/service_plugin.cpp | 2 +- tests/utc/audio-manager/test_audio_manager.cpp | 2 +- tests/utc/client-manager/test_client_manager.cpp | 2 +- tests/utc/config/test_config.cpp | 2 +- tests/utc/service-main/test_service_main.cpp | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/inc/application_manager.h b/inc/application_manager.h index 08b2586..0bb6fea 100644 --- a/inc/application_manager.h +++ b/inc/application_manager.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index e4edbba..0de9479 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/client_manager.h b/inc/client_manager.h index abcb770..b174b14 100644 --- a/inc/client_manager.h +++ b/inc/client_manager.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/preference_manager.h b/inc/preference_manager.h index fa33d7f..79d3734 100644 --- a/inc/preference_manager.h +++ b/inc/preference_manager.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/preference_manager_vconf.h b/inc/preference_manager_vconf.h index bae3670..7af61cb 100644 --- a/inc/preference_manager_vconf.h +++ b/inc/preference_manager_vconf.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_config.h b/inc/service_config.h index d77a4a0..5a87e0f 100644 --- a/inc/service_config.h +++ b/inc/service_config.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 8b29954..e6778c4 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_ipc_dbus_dispatcher.h b/inc/service_ipc_dbus_dispatcher.h index 70a5f5d..ae36c70 100644 --- a/inc/service_ipc_dbus_dispatcher.h +++ b/inc/service_ipc_dbus_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_main.h b/inc/service_main.h index 4a6ddfa..46a4b12 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_plugin.h b/inc/service_plugin.h index 36ffd78..35a5e12 100644 --- a/inc/service_plugin.h +++ b/inc/service_plugin.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/inc/service_plugin_interface.h b/inc/service_plugin_interface.h index 5d622d4..669d1c4 100644 --- a/inc/service_plugin_interface.h +++ b/inc/service_plugin_interface.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/plugins/wakeup-manager/inc/wakeup_policy_external.h b/plugins/wakeup-manager/inc/wakeup_policy_external.h index 846330f..366f272 100644 --- a/plugins/wakeup-manager/inc/wakeup_policy_external.h +++ b/plugins/wakeup-manager/inc/wakeup_policy_external.h @@ -1,5 +1,5 @@ /* - * Copyright 2018 Samsung Electronics Co., Ltd + * Copyright 2018 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. diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index b3863ad..9418b96 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/client_manager.cpp b/src/client_manager.cpp index b91ab4a..b89ed1c 100644 --- a/src/client_manager.cpp +++ b/src/client_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/preference_manager_vconf.cpp b/src/preference_manager_vconf.cpp index 823cbad..985ae38 100644 --- a/src/preference_manager_vconf.cpp +++ b/src/preference_manager_vconf.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/service_config.cpp b/src/service_config.cpp index 97b90ee..484b5e1 100644 --- a/src/service_config.cpp +++ b/src/service_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 7848880..fa3867d 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/service_ipc_dbus_dispatcher.cpp b/src/service_ipc_dbus_dispatcher.cpp index df43612..26e7ac1 100644 --- a/src/service_ipc_dbus_dispatcher.cpp +++ b/src/service_ipc_dbus_dispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/service_main.cpp b/src/service_main.cpp index b023aa4..7cb5fd9 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 6348c8a..f96f922 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 Samsung Electronics Co., Ltd + * 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. diff --git a/tests/utc/audio-manager/test_audio_manager.cpp b/tests/utc/audio-manager/test_audio_manager.cpp index 999a1d9..a2eb666 100644 --- a/tests/utc/audio-manager/test_audio_manager.cpp +++ b/tests/utc/audio-manager/test_audio_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018 Samsung Electronics Co., Ltd + * 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. diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp index ef1357f..d23428d 100644 --- a/tests/utc/client-manager/test_client_manager.cpp +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018 Samsung Electronics Co., Ltd + * 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. diff --git a/tests/utc/config/test_config.cpp b/tests/utc/config/test_config.cpp index d9b6299..00b6805 100644 --- a/tests/utc/config/test_config.cpp +++ b/tests/utc/config/test_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018 Samsung Electronics Co., Ltd + * 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. diff --git a/tests/utc/service-main/test_service_main.cpp b/tests/utc/service-main/test_service_main.cpp index 1ff69ef..b7313c5 100644 --- a/tests/utc/service-main/test_service_main.cpp +++ b/tests/utc/service-main/test_service_main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2018 Samsung Electronics Co., Ltd + * 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. -- 2.7.4 From f47d5825126b0183627cb6840c360da88cc3e104 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 6 Apr 2020 18:49:57 +0900 Subject: [PATCH 07/16] Unify member function names in CServiceIpcDbus Change-Id: I5f85cdec79077b12dc6852de912aecc22d03bf91 --- inc/service_ipc_dbus.h | 6 +++--- src/service_ipc_dbus.cpp | 6 +++--- src/service_main.cpp | 14 +++++++------- src/service_plugin.cpp | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index e6778c4..9c5e40b 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -38,13 +38,13 @@ public: int send_hello(int pid); int send_error_message(int reason, const char* err_msg); int send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size); - int active_state_change(int pid, int state); + int change_active_state(int pid, int state); int send_preprocessing_information(int pid, const char* app_id); int send_streaming_section_changed(int pid, int section); int send_preprocessing_result(int pid, bool result); int send_wakeup_engine_command(int pid, const char* command); - int service_state_change(int pid, int state); - int voice_key_status_change(int pid, int status); + int change_service_state(int pid, int state); + int change_voice_key_status(int pid, int status); int masc_ui_dbus_send_hello(void); int masc_ui_dbus_send_asr_result(int pid, int event, const char* asr_result); int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json); diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index fa3867d..72c18b4 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -281,7 +281,7 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u return 0; } -int CServiceIpcDbus::active_state_change(int pid, int state) +int CServiceIpcDbus::change_active_state(int pid, int state) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -547,7 +547,7 @@ int CServiceIpcDbus::send_wakeup_engine_command(int pid, const char* command) return 0; } -int CServiceIpcDbus::service_state_change(int pid, int state) +int CServiceIpcDbus::change_service_state(int pid, int state) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -597,7 +597,7 @@ int CServiceIpcDbus::service_state_change(int pid, int state) return 0; } -int CServiceIpcDbus::voice_key_status_change(int pid, int status) +int CServiceIpcDbus::change_voice_key_status(int pid, int status) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; diff --git a/src/service_main.cpp b/src/service_main.cpp index 7cb5fd9..b3d4dff 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -127,7 +127,7 @@ int CServiceMain::mas_client_send_voice_key_status_change(int pid, ma_voice_key_ int ret = -1; MAS_LOGD("[Enter] pid(%d)", pid); - ret = mServiceIpc.voice_key_status_change(pid, status); + ret = mServiceIpc.change_voice_key_status(pid, status); if (0 != ret) { MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret); } @@ -428,7 +428,7 @@ int CServiceMain::mas_ui_client_change_assistant(const char* appid) mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus); } - mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_ACTIVE); MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL")); /* int ret = mServicePlugin.start_streaming_utterance_data(); @@ -829,7 +829,7 @@ int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) if (mCurrentClientInfo != prev_selection) { if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) { int pid = mas_get_client_pid_by_appid(mClientInfo[prev_selection].appid); - mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); + mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -855,7 +855,7 @@ int CServiceMain::mas_set_current_client_by_appid(const char *appid) if (mCurrentClientInfo != prev_selection) { if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) { int pid = mas_get_client_pid_by_appid(mClientInfo[prev_selection].appid); - mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); + mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -1102,7 +1102,7 @@ int CServiceMain::mas_set_current_service_state(ma_service_state_e state) int pid = mClientManager.find_client_pid_by_index(i); if (-1 != pid) { - int ret = mServiceIpc.service_state_change(pid, state); + int ret = mServiceIpc.change_service_state(pid, state); if (0 != ret) { MAS_LOGE("[ERROR] Fail to set service state change to %d, ret(%d)", pid, ret); } @@ -1365,7 +1365,7 @@ int CServiceMain::on_initialize(int pid) { if (0 == mWakeupClientAppId.compare(pid_appid)) { mWakeupClientAppId.clear(); - mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_ACTIVE); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { MAS_LOGE("[ERROR] mWakeupClientAppId and appid differ : %s %s", @@ -1375,7 +1375,7 @@ int CServiceMain::on_initialize(int pid) { MAS_LOGD("MA client connected, but its appid does not match with current maclient"); } - mServiceIpc.service_state_change(pid, mas_get_current_service_state()); + mServiceIpc.change_service_state(pid, mas_get_current_service_state()); } else { MAS_LOGE("[ERROR] Fail to retrieve appid"); } diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index f96f922..4fbddce 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -114,7 +114,7 @@ static Eina_Bool process_wakeup_event_by_appid_timer(void* data) service_main->mas_set_current_client_by_appid(appid); if ((pid = service_main->mas_get_client_pid_by_appid(appid)) != -1) { service_main->mas_client_send_preprocessing_information(pid); - service_ipc->active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + service_ipc->change_active_state(pid, MA_ACTIVE_STATE_ACTIVE); service_main->mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { // Appropriate MA Client not available, trying to launch new one @@ -494,7 +494,7 @@ static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e s } if (service_ipc && service_main) { int pid = service_main->mas_get_current_client_pid(); - int ret = service_ipc->voice_key_status_change(pid, status); + int ret = service_ipc->change_voice_key_status(pid, status); if (0 != ret) { MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret); } -- 2.7.4 From d9b8161ebd21e4da84d0ddaa4c1f4adbfce32ec5 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 6 Apr 2020 19:16:18 +0900 Subject: [PATCH 08/16] Fix defects detected by static analysis tool Change-Id: I9af8980b3d3f15ded3fa261ec957debe7adc5365 --- inc/service_config.h | 9 +++------ plugins/wakeup-manager/inc/wakeup_manager.h | 5 +++-- plugins/wakeup-manager/src/wakeup_manager.cpp | 1 + src/service_main.cpp | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/inc/service_config.h b/inc/service_config.h index 5a87e0f..5604ed2 100644 --- a/inc/service_config.h +++ b/inc/service_config.h @@ -28,9 +28,6 @@ extern "C" { #endif -#define MAX_WAKEUP_LIST_NUM 32 -#define MAX_SUPPORTED_LANGUAGE_NUM 128 - /************************************************************************************** *** Definitions for xml file *************************************************************************************/ @@ -79,10 +76,10 @@ typedef struct ma_assistant_info_s { const char* app_id; const char* name; const char* icon_path; - const char* wakeup_list[MAX_WAKEUP_LIST_NUM]; - const char* wakeup_language[MAX_WAKEUP_LIST_NUM]; + const char* wakeup_list[MAX_WAKEUP_WORDS_NUM]; + const char* wakeup_language[MAX_WAKEUP_WORDS_NUM]; int cnt_wakeup; - const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM]; + const char* supported_lang[MAX_SUPPORTED_LANGUAGES_NUM]; int cnt_lang; const char* wakeup_engine; bool custom_ui_option; diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 3b6a00b..8e98d93 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -226,7 +226,8 @@ private: bool mVoiceKeyPressed{false}; string mCurrentLanguage; string mCurrentDefaultAssistant; - VOICE_KEY_SUPPORT_MODE mCurrentVoiceKeySupportMode; + /* Assume Push-to-talk is the default mode */ + VOICE_KEY_SUPPORT_MODE mCurrentVoiceKeySupportMode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK}; STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE}; Ecore_Timer* mStreamingDurationTimer{nullptr}; @@ -239,4 +240,4 @@ private: } // wakeup } // multiassistant -#endif /* _WAKEUP_MANAGER_H_ */ \ No newline at end of file +#endif /* _WAKEUP_MANAGER_H_ */ diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index bce479c..e7cdbf0 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -509,6 +509,7 @@ bool CWakeupManager::change_voice_key_status(ma_voice_key_status_e status) { MA_VOICE_KEY_STATUS_RELEASED_AFTER_TAP == status) { mVoiceKeyPressed = false; } + return true; } bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data, int len) diff --git a/src/service_main.cpp b/src/service_main.cpp index b3d4dff..4628c15 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -609,7 +609,7 @@ int CServiceMain::initialize_service_plugin(void) } } } - for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) { + for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) { if (mClientInfo[loop].supported_language[inner_loop] && 0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { MAS_LOGD("Adding language %s for app %s", -- 2.7.4 From 278937a68fa3136e2a3c7d80ccd0515df401e575 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 3 Apr 2020 15:08:40 +0900 Subject: [PATCH 09/16] Fix build break caused by incorrect type inference Change-Id: Idc32c9428d0592a60b01a0a156fa924d6d64c23e (cherry picked from commit bdf4022693ee0c5ec2e0b2d4bcb50a1806a7faf2) --- .../dependency-default/src/dependency_default_button.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp index f3684a8..f11ee97 100644 --- a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp +++ b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp @@ -59,7 +59,7 @@ static Eina_Bool _key_up_cb(void* data, int type, void* event) chrono::time_point current_time_point; current_time_point = chrono::system_clock::now(); auto diff = current_time_point - g_last_key_pressed; - auto milliseconds = chrono::duration_cast(diff).count(); + long long int milliseconds = chrono::duration_cast(diff).count(); LOGD("milliseconds : %lld", milliseconds); mas_plugin_event_e event; if (milliseconds < g_voice_key_tap_duration) { @@ -160,4 +160,4 @@ void dependency_default_button_set_voice_key_tap_duration(float duration) void dependency_default_button_unset_voice_key_tap_duration(void) { g_voice_key_tap_duration = DEFAULT_KEY_TAP_DURATION; -} \ No newline at end of file +} -- 2.7.4 From ed22efad158fc774bcb2b8907e316b0f50230ef7 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 23 Mar 2020 12:25:52 +0900 Subject: [PATCH 10/16] Reload plugin on voice assistant related pkgmgr events Change-Id: I1c00665a138d4a55d2d2517675fada5ef5ea963e --- src/multi_assistant_service.c | 45 +++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index d815200..bc84cc1 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -732,6 +732,7 @@ static void mas_active_state_changed_cb(keynode_t* key, void* data) static int init_plugin(void) { + MAS_LOGI("[ENTER]"); if (0 != multi_assistant_service_plugin_initialize()) { MAS_LOGE("Fail to ws intialize"); return -1; @@ -1382,28 +1383,52 @@ ma_service_state_e mas_get_current_service_state() return g_current_service_state; } -static int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) +static bool is_wakeup_engine(const pkgmgrinfo_appinfo_h handle) { + bool is_wakeup_engine = false; char *appid = NULL; int ret = pkgmgrinfo_appinfo_get_appid (handle, &appid); if (PMINFO_R_OK == ret && NULL != appid) { - int *result = (int*)user_data; - if (result) { - for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) { - if (g_maclient_info[loop].used) { - LOGD("comparing appid : %s %s", g_maclient_info[loop].wakeup_engine, appid); - if (0 == strncmp(g_maclient_info[loop].wakeup_engine, appid, MAX_APPID_LEN)) { - *result = 1; - } + for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) { + if (g_maclient_info[loop].used) { + LOGD("comparing appid : %s %s", g_maclient_info[loop].wakeup_engine, appid); + if (0 == strncmp(g_maclient_info[loop].wakeup_engine, appid, MAX_APPID_LEN)) { + is_wakeup_engine = true; } } } } else { LOGE("pkgmgrinfo_appinfo_get_appid failed! error code=%d", ret); - return 0; } + return is_wakeup_engine; +} + +static bool is_voice_assistant(const pkgmgrinfo_appinfo_h handle) +{ + bool is_voice_assistant = false; + char* metadata_value = NULL; + const char* voice_assistant_metadata = "http://tizen.org/metadata/multi-assistant/name"; + int ret = pkgmgrinfo_appinfo_get_metadata_value(handle, voice_assistant_metadata, &metadata_value); + if (PMINFO_R_OK == ret && NULL != metadata_value) { + is_voice_assistant = true; + } else { + LOGE("pkgmgrinfo_appinfo_get_metadata_value failed! error code=%d", ret); + } + return is_voice_assistant; +} + +static int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) +{ + int *result = (int*)user_data; + if (result) { + if (is_voice_assistant(handle)) { + *result = 1; + } else if (is_wakeup_engine(handle)) { + *result = 1; + } + } return 0; } -- 2.7.4 From 6e8c939c34ec19ada63588088e52a4e4c697b9ac Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 10 Apr 2020 09:18:15 +0900 Subject: [PATCH 11/16] Bump version to 0.2.30 Change-Id: Ia36166583b59e9ad9ab0d332bb3c8546bc908632 --- 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 58de9dd..0476cfd 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 74d58b2..ad13329 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.29 +Version: 0.2.30 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From bb02643c98fa35f824f55a7bdbfd250ec016753e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 10 Apr 2020 11:00:08 +0900 Subject: [PATCH 12/16] Fix defects detected by static analysis tool Change-Id: Ief868cf1c63021d83370e4b29f0079cf7286d713 --- src/service_config.cpp | 11 +++++++---- src/service_main.cpp | 12 ++++-------- src/service_plugin.cpp | 51 +++++++++++++++++++++----------------------------- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/service_config.cpp b/src/service_config.cpp index 484b5e1..a86b491 100644 --- a/src/service_config.cpp +++ b/src/service_config.cpp @@ -291,6 +291,8 @@ int CServiceConfig::load_custom_wake_words(const char* app_id, char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) { + const char delimeter = '|'; + /* Add 1 for additional pipe character */ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)]; char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)]; @@ -324,8 +326,8 @@ int CServiceConfig::load_custom_wake_words(const char* app_id, char *language_end = NULL; int index = 0; while (index < MAX_WAKEUP_WORDS_NUM) { - word_end = strchrnul(word_start, '|'); - language_end = strchrnul(language_start, '|'); + word_end = strchrnul(word_start, delimeter); + language_end = strchrnul(language_start, delimeter); if ('\0' == *word_end || '\0' == *language_end) break; *word_end = '\0'; *language_end = '\0'; @@ -346,6 +348,7 @@ int CServiceConfig::save_custom_wake_words(const char* app_id, char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) { + const char* delimeter = "|"; /* Add 1 for additional pipe character */ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)]; char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)]; @@ -356,11 +359,11 @@ int CServiceConfig::save_custom_wake_words(const char* app_id, int wakeup_words_len = strlen(wakeup_words); strncat(wakeup_words, wakeup_word_storage[loop], sizeof(wakeup_words) - wakeup_words_len - 1); - strcat(wakeup_words, "|"); + strncat(wakeup_words, delimeter, strlen(delimeter)); int wakeup_languages_len = strlen(wakeup_languages); strncat(wakeup_languages, wakeup_language_storage[loop], sizeof(wakeup_languages) - wakeup_languages_len - 1); - strcat(wakeup_languages, "|"); + strncat(wakeup_languages, delimeter, strlen(delimeter)); } } wakeup_words[sizeof(wakeup_words) - 1] = '\0'; diff --git a/src/service_main.cpp b/src/service_main.cpp index 4628c15..8fd818a 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -586,19 +586,16 @@ int CServiceMain::initialize_service_plugin(void) if (0 == mServiceConfig.get_assistant_info(mas_assistant_info_cb, this)) { for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { int inner_loop; - if (mClientInfo[loop].used && mClientInfo[loop].appid && - 0 < strlen(mClientInfo[loop].appid)) { + if (0 < strlen(mClientInfo[loop].appid)) { mServiceConfig.load_custom_wake_words(mClientInfo[loop].appid, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); - if (mClientInfo[loop].wakeup_engine && - 0 < strlen(mClientInfo[loop].wakeup_engine)) { + if (0 < strlen(mClientInfo[loop].wakeup_engine)) { mServicePlugin.set_assistant_wakeup_engine( mClientInfo[loop].appid, mClientInfo[loop].wakeup_engine); } for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { - if (mClientInfo[loop].wakeup_word[inner_loop] && - 0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { + if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { MAS_LOGD("Registering wakeup word %s for app %s", mClientInfo[loop].wakeup_word[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_wakeup_word( @@ -610,8 +607,7 @@ int CServiceMain::initialize_service_plugin(void) } } for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) { - if (mClientInfo[loop].supported_language[inner_loop] && - 0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { + if (0 < strlen(mClientInfo[loop].supported_language[inner_loop])) { MAS_LOGD("Adding language %s for app %s", mClientInfo[loop].supported_language[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_language( diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 4fbddce..f12323e 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -398,11 +398,10 @@ static void __error_cb(int error, const char* err_msg, void* user_data) { MAS_LOGD("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg); - CServiceIpcDbus* service_ipc = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus* service_ipc = plugin->get_service_ipc(); if (plugin->is_ui_panel_enabled() && service_ipc) { int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg); if (0 != ret) { @@ -413,11 +412,10 @@ static void __error_cb(int error, const char* err_msg, void* user_data) static void __setting_changed_cb(void *user_data) { - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceMain* service_main = plugin->get_service_main(); if (service_main) { service_main->mas_prelaunch_default_assistant(); service_main->mas_update_voice_key_support_mode(); @@ -429,13 +427,11 @@ static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e sec { MAS_LOGD("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_current_client_pid(); int ret = service_ipc->send_streaming_section_changed(pid, (int)section); @@ -449,13 +445,11 @@ static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target { MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_client_pid_by_appid(assistant_name); if (-1 != pid) { @@ -471,11 +465,10 @@ static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* us { MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state); - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceMain* service_main = plugin->get_service_main(); if (service_main) { service_main->mas_set_current_service_state(state); } @@ -485,13 +478,11 @@ static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e s { MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status); - CServiceIpcDbus *service_ipc = nullptr; - CServiceMain* service_main = nullptr; CServicePlugin *plugin = static_cast(user_data); - if (plugin) { - service_ipc = plugin->get_service_ipc(); - service_main = plugin->get_service_main(); - } + if (nullptr == plugin) return; + + CServiceIpcDbus *service_ipc = plugin->get_service_ipc(); + CServiceMain* service_main = plugin->get_service_main(); if (service_ipc && service_main) { int pid = service_main->mas_get_current_client_pid(); int ret = service_ipc->change_voice_key_status(pid, status); -- 2.7.4 From d7b43ec34d43be537fe296dc091bee5493ed147e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 6 Apr 2020 19:16:18 +0900 Subject: [PATCH 13/16] Fix defects detected by static analysis tool Change-Id: I9af8980b3d3f15ded3fa261ec957debe7adc5365 --- inc/multi_assistant_config.h | 18 +++++------------- inc/multi_assistant_main.h | 20 +++++++++++++++++--- inc/multi_assistant_service_client.h | 23 ++++++++++++++++++----- inc/multi_wakeup_recognizer.h | 4 ++-- plugins/wakeup-manager/inc/wakeup_manager.h | 5 +++-- plugins/wakeup-manager/src/wakeup_manager.cpp | 1 + src/multi_assistant_service.c | 20 +------------------- 7 files changed, 47 insertions(+), 44 deletions(-) diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index a5810ac..2999533 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -21,14 +21,13 @@ #include #include +#include "multi_assistant_main.h" + #ifdef __cplusplus extern "C" { #endif -#define MAX_WAKEUP_LIST_NUM 32 -#define MAX_SUPPORTED_LANGUAGE_NUM 128 - /************************************************************************************** *** Definitions for xml file *************************************************************************************/ @@ -57,21 +56,14 @@ extern "C" #define VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK "tap_to_talk" #define VOICE_KEY_SUPPORT_MODE_STRING_ALL "all" -typedef enum { - VOICE_KEY_SUPPORT_MODE_NONE, - VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK, - VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK, - VOICE_KEY_SUPPORT_MODE_ALL, -} VOICE_KEY_SUPPORT_MODE; - typedef struct { const char* app_id; const char* name; const char* icon_path; - const char* wakeup_list[MAX_WAKEUP_LIST_NUM]; - const char* wakeup_language[MAX_WAKEUP_LIST_NUM]; + const char* wakeup_list[MAX_WAKEUP_WORDS_NUM]; + const char* wakeup_language[MAX_WAKEUP_WORDS_NUM]; int cnt_wakeup; - const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM]; + const char* supported_lang[MAX_SUPPORTED_LANGUAGES_NUM]; int cnt_lang; const char* wakeup_engine; bool custom_ui_option; diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h index 27250ef..016c5a4 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -1,5 +1,5 @@ -#ifndef __MULTI_ASSISTANT_SERVICE_H__ -#define __MULTI_ASSISTANT_SERVICE_H__ +#ifndef __MULTI_ASSISTANT_MAIN_H__ +#define __MULTI_ASSISTANT_MAIN_H__ #include #include @@ -92,4 +92,18 @@ #define MAS_UI_METHOD_SEND_RECOGNITION_RESULT "mas_ui_method_send_recognition_result" #define MAS_UI_METHOD_ENABLE_COMMON_UI "mas_ui_method_enable_common_ui" -#endif /* __MULTI_ASSISTANT_SERVICE_H__ */ +#define MAX_WAKEUP_WORDS_NUM 255 +#define MAX_WAKEUP_WORD_LEN 32 +#define MAX_SUPPORTED_LANGUAGES_NUM 255 +#define MAX_SUPPORTED_LANGUAGE_LEN 16 + +#define MAX_APPID_LEN 255 + +typedef enum { + VOICE_KEY_SUPPORT_MODE_NONE, + VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK, + VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK, + VOICE_KEY_SUPPORT_MODE_ALL, +} VOICE_KEY_SUPPORT_MODE; + +#endif /* __MULTI_ASSISTANT_MAIN_H__ */ diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h index be2e984..76a9392 100644 --- a/inc/multi_assistant_service_client.h +++ b/inc/multi_assistant_service_client.h @@ -15,18 +15,17 @@ */ -#ifndef _MULTI_ASSISTANT_SERVICE_H_ -#define _MULTI_ASSISTANT_SERVICE_H_ +#ifndef _MULTI_ASSISTANT_SERVICE_CLIENT_H_ +#define _MULTI_ASSISTANT_SERVICE_CLIENT_H_ #include +#include "multi_assistant_main.h" #ifdef __cplusplus extern "C" { #endif -#define MAX_APPID_LEN 255 - typedef enum { CLIENT_LAUNCH_MODE_ACTIVATION, CLIENT_LAUNCH_MODE_PRELAUNCH, @@ -119,9 +118,23 @@ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event); int mas_update_voice_key_support_mode(); +typedef struct { + bool used; + char appid[MAX_APPID_LEN]; + char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN]; + char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; + char wakeup_engine[MAX_APPID_LEN]; + char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; + bool custom_ui_option; + VOICE_KEY_SUPPORT_MODE voice_key_support_mode; + float voice_key_tap_duration; + + ma_preprocessing_allow_mode_e preprocessing_allow_mode; + char preprocessing_allow_appid[MAX_APPID_LEN]; +} ma_client_info; #ifdef __cplusplus } #endif -#endif /* _MULTI_ASSISTANT_SERVICE_H_ */ +#endif /* _MULTI_ASSISTANT_SERVICE_CLIENT_H_ */ diff --git a/inc/multi_wakeup_recognizer.h b/inc/multi_wakeup_recognizer.h index d5f8fb0..a9f4b45 100644 --- a/inc/multi_wakeup_recognizer.h +++ b/inc/multi_wakeup_recognizer.h @@ -28,9 +28,9 @@ extern "C" { #endif -typedef void (*wakeup_service_wakeup_event_cb)(mas_wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data); +typedef void (*wakeup_service_wakeup_event_cb)(mas_wakeup_event_info wakeup_info, void* user_data); -typedef void (*wakeup_service_speech_streaming_cb)(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data); +typedef void (*wakeup_service_speech_streaming_cb)(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data); typedef void (*wakeup_service_speech_status_cb)(mas_speech_status_e status, void *user_data); diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 0f2d6ed..de7cb11 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -225,7 +225,8 @@ private: bool mVoiceKeyPressed{false}; string mCurrentLanguage; string mCurrentDefaultAssistant; - VOICE_KEY_SUPPORT_MODE mCurrentVoiceKeySupportMode; + /* Assume Push-to-talk is the default mode */ + VOICE_KEY_SUPPORT_MODE mCurrentVoiceKeySupportMode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK}; STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE}; Ecore_Timer* mStreamingDurationTimer{nullptr}; @@ -238,4 +239,4 @@ private: } // wakeup } // multiassistant -#endif /* _WAKEUP_MANAGER_H_ */ \ No newline at end of file +#endif /* _WAKEUP_MANAGER_H_ */ diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index ab2b8a4..b0ddfd1 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -499,6 +499,7 @@ bool CWakeupManager::change_voice_key_status(ma_voice_key_status_e status) { MA_VOICE_KEY_STATUS_RELEASED_AFTER_TAP == status) { mVoiceKeyPressed = false; } + return true; } bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data, int len) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index bc84cc1..fcbd186 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -45,24 +45,6 @@ static const char *g_current_lang = "en_US"; #define WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE "db/multi-assistant/prelaunch_mode" #define MAX_MACLIENT_INFO_NUM 16 -#define MAX_WAKEUP_WORDS_NUM 255 -#define MAX_WAKEUP_WORD_LEN 32 -#define MAX_SUPPORTED_LANGUAGES_NUM 255 -#define MAX_SUPPORTED_LANGUAGE_LEN 16 -typedef struct { - bool used; - char appid[MAX_APPID_LEN]; - char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN]; - char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; - char wakeup_engine[MAX_APPID_LEN]; - char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; - bool custom_ui_option; - VOICE_KEY_SUPPORT_MODE voice_key_support_mode; - float voice_key_tap_duration; - - ma_preprocessing_allow_mode_e preprocessing_allow_mode; - char preprocessing_allow_appid[MAX_APPID_LEN]; -} ma_client_info; static ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM]; @@ -770,7 +752,7 @@ static int init_plugin(void) } } } - for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) { + for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) { if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) { MAS_LOGD("Adding language %s for app %s", g_maclient_info[loop].supported_language[inner_loop], g_maclient_info[loop].appid); -- 2.7.4 From ec738d0242ca5af0e7c047766b640487c2f810b0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 13 Apr 2020 18:49:48 +0900 Subject: [PATCH 14/16] Fix finding pid by appid fails due to invalid parameter passing Change-Id: I96e83d821526cbf1a64b6d059e544893970c5ac3 --- src/client_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client_manager.cpp b/src/client_manager.cpp index b89ed1c..f9cf2f9 100644 --- a/src/client_manager.cpp +++ b/src/client_manager.cpp @@ -147,7 +147,7 @@ int CClientManager::find_client_pid_by_appid(std::string appid) ma_client_s* client = find_client_by_appid(appid); if (client) { - bool running = mApplicationManager->is_application_running(pid); + bool running = mApplicationManager->is_application_running(client->pid); if (false == running) { MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid.c_str(), client->pid); -- 2.7.4 From 52ada0b2d27a4f64872456b5e8ec4f45a45a195c Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 13 Apr 2020 20:16:41 +0900 Subject: [PATCH 15/16] Add -Wno-stringop-overflow option for fixing build error False alarm causes build break when using strncat, thus adding a compile option to disable it. Change-Id: Icbc8fb63c2d4c87f007e5b979268dcd40f2467f1 --- packaging/org.tizen.multi-assistant-service.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 60bfeed..63bca4f 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -55,8 +55,8 @@ LDFLAGS="$LDFLAGS -Wl,-z -Wl,nodelete" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif -export CFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow" -export CXXFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow" +export CFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow -Wno-stringop-overflow" +export CXXFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow -Wno-stringop-overflow" export LDFLAGS %cmake \ -- 2.7.4 From 4f2c95c524c209ea3a5b32dbee1fc71308a6aade Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 13 Apr 2020 20:19:16 +0900 Subject: [PATCH 16/16] Replace int with pid_t where applicable Change-Id: Ic388b17e4b37072eda5861d39b92345b8553d55b --- inc/application_manager.h | 4 ++-- inc/application_manager_aul.h | 4 ++-- src/application_manager_aul.cpp | 4 ++-- tests/utc/client-manager/test_client_manager.cpp | 4 ++-- tests/utc/service-main/test_service_main.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/inc/application_manager.h b/inc/application_manager.h index 0bb6fea..1effd84 100644 --- a/inc/application_manager.h +++ b/inc/application_manager.h @@ -27,11 +27,11 @@ extern "C" { class IApplicationManager { public: - virtual bool is_application_running(int pid) = 0; + virtual bool is_application_running(pid_t pid) = 0; virtual bool is_application_running(const std::string& appid) = 0; virtual bool bring_app_to_foreground(const std::string& appid) = 0; virtual bool launch_app_async(const std::string& appid, bool background) = 0; - virtual boost::optional get_appid_by_pid(int pid) = 0; + virtual boost::optional get_appid_by_pid(pid_t pid) = 0; }; #ifdef __cplusplus diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index 0de9479..4b46f59 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -29,11 +29,11 @@ public: CApplicationManagerAul(); ~CApplicationManagerAul(); - virtual bool is_application_running(int pid) override; + virtual bool is_application_running(pid_t pid) override; virtual bool is_application_running(const std::string& appid) override; virtual bool bring_app_to_foreground(const std::string& appid) override; virtual bool launch_app_async(const std::string& appid, bool background) override; - virtual boost::optional get_appid_by_pid(int pid) override; + virtual boost::optional get_appid_by_pid(pid_t pid) override; }; #ifdef __cplusplus diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 9418b96..41ae5f2 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -28,7 +28,7 @@ CApplicationManagerAul::~CApplicationManagerAul() { } -bool CApplicationManagerAul::is_application_running(int pid) +bool CApplicationManagerAul::is_application_running(pid_t pid) { int status = aul_app_get_status_bypid(pid); if (0 > status) { @@ -98,7 +98,7 @@ bool CApplicationManagerAul::launch_app_async(const std::string& appid, bool bac return ret; } -boost::optional CApplicationManagerAul::get_appid_by_pid(int pid) +boost::optional CApplicationManagerAul::get_appid_by_pid(pid_t pid) { boost::optional ret; diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp index d23428d..da5cb94 100644 --- a/tests/utc/client-manager/test_client_manager.cpp +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -26,11 +26,11 @@ public: CDummyApplicationManager() {}; virtual ~CDummyApplicationManager() {}; - bool is_application_running(int pid) { return true; } + bool is_application_running(pid_t pid) { return true; } bool is_application_running(const std::string& appid) { return true; } bool bring_app_to_foreground(const std::string& appid) { return true; } bool launch_app_async(const std::string& appid, bool background) { return true; } - boost::optional get_appid_by_pid(int pid) { return boost::optional{}; } + boost::optional get_appid_by_pid(pid_t pid) { return boost::optional{}; } }; class StorageWithNoClient : public testing::Test diff --git a/tests/utc/service-main/test_service_main.cpp b/tests/utc/service-main/test_service_main.cpp index b7313c5..b14cf72 100644 --- a/tests/utc/service-main/test_service_main.cpp +++ b/tests/utc/service-main/test_service_main.cpp @@ -28,7 +28,7 @@ public: CDummyApplicationManager() {}; ~CDummyApplicationManager() {}; - bool is_application_running(int pid) override { return false; } + bool is_application_running(pid_t pid) override { return false; } bool is_application_running(const std::string& appid) override { return false; } bool bring_app_to_foreground(const std::string& appid) override { @@ -41,7 +41,7 @@ public: launched_option_background = background; return true; } - boost::optional get_appid_by_pid(int pid) override { return boost::optional{}; } + boost::optional get_appid_by_pid(pid_t pid) override { return boost::optional{}; } public: boost::optional launched_appid; boost::optional launched_option_background; -- 2.7.4