/*
- * 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.
#include <service_app.h>
#include <app_manager.h>
#include <app.h>
-#include <aul.h>
-#include <aul_svc.h>
#include <malloc.h>
#include <Ecore.h>
#include <vconf.h>
-#include <pkgmgr-info.h>
#include <stdio.h>
#include <stdlib.h>
static CServiceMain* g_service_main = nullptr;
-int CServiceMain::ma_client_create(ma_client_s *info)
-{
- if (NULL == info) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return -1;
- }
-
- ma_client_s* data = NULL;
-
- data = (ma_client_s*)calloc(1, sizeof(ma_client_s));
- if (NULL == data) {
- MAS_LOGE("[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
- return -1;// MA_ERROR_OUT_OF_MEMORY;
- }
-
- *data = *info;
- g_client_list = g_slist_append(g_client_list, data);
-
- return 0;
-}
-
-int CServiceMain::ma_client_destroy(ma_client_s *client)
-{
- if (NULL == client) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return -1;// MA_ERROR_OPERATION_FAILED;
- }
-
- g_client_list = g_slist_remove(g_client_list, client);
-
- free(client);
- client = NULL;
-
- return 0;
-}
-
-ma_client_s* CServiceMain::ma_client_find_by_appid(const char *appid)
-{
- if (NULL == appid) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return NULL;
- }
-
- ma_client_s *data = NULL;
-
- int count = g_slist_length(g_client_list);
- int i;
-
- for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
-
- if (NULL != data) {
- if (0 == strncmp(data->appid, appid, MAX_APPID_LEN)) {
- return data;
- }
- }
- }
-
- MAS_LOGE("[ERROR] client Not found");
-
- return NULL;
-}
-
-ma_client_s* CServiceMain::ma_client_find_by_pid(int pid)
-{
- ma_client_s *data = NULL;
-
- int count = g_slist_length(g_client_list);
- int i;
-
- for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
-
- if (NULL != data) {
- if (data->pid == pid) {
- return data;
- }
- }
- }
-
- MAS_LOGE("[ERROR] client Not found");
-
- return NULL;
-}
-
bool CServiceMain::check_preprocessing_assistant_exists()
{
bool ret = false;
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
+ boost::optional<std::string> preprocessing_appid =
+ mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (preprocessing_appid) {
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used) {
- if (strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- ma_client_s* client = ma_client_find_by_appid(vconf_str);
- if (client && client->pid > 0) {
- ret = true;
- }
+ if (mClientInfo[loop].used &&
+ strncmp((*preprocessing_appid).c_str(), mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ if (mClientManager.check_client_validity_by_appid(*preprocessing_appid)) {
+ ret = true;
}
}
}
- free(vconf_str);
- vconf_str = NULL;
}
MAS_LOGD("result : %d", ret);
bool ret = false;
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
- if (strncmp(vconf_str, appid, MAX_APPID_LEN) == 0) {
+ boost::optional<std::string> preprocessing_appid =
+ mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (preprocessing_appid) {
+ if (strncmp((*preprocessing_appid).c_str(), appid, MAX_APPID_LEN) == 0) {
ret = true;
}
- free(vconf_str);
- vconf_str = NULL;
}
return ret;
}
-int CServiceMain::mas_client_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"));
-
- /* Remove existing client that has same appid, if there's any */
- ma_client_s *old_client = NULL;
- old_client = ma_client_find_by_appid(appid);
- if (old_client) {
- ma_client_destroy(old_client);
- old_client = NULL;
- }
-
- /* And remove a client that has same pid also */
- old_client = ma_client_find_by_pid(pid);
- if (old_client) {
- ma_client_destroy(old_client);
- old_client = NULL;
- }
-
- ma_client_s new_client;
- new_client.pid = pid;
- strncpy(new_client.appid, appid, MAX_APPID_LEN);
- new_client.appid[MAX_APPID_LEN - 1] = '\0';
- ma_client_create(&new_client);
-
- const char *current_maclient_appid = NULL;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
- }
-
- mas_client_send_preprocessing_information(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)) {
- MAS_LOGD("MA client with current maclient appid connected!");
-
- if (0 == g_wakeup_maclient_appid.compare(appid)) {
- g_wakeup_maclient_appid.clear();
- mas_client_activate(pid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
- } else {
- MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s",
- g_wakeup_maclient_appid.c_str(), appid);
- }
- } else {
- MAS_LOGD("MA client connected, but its appid does not match with current maclient");
- }
-
- mServiceIpc.service_state_change(pid, mas_get_current_service_state());
- } else {
- MAS_LOGE("[ERROR] Fail to retrieve appid");
- }
-
- return 0;
-}
-
-int CServiceMain::mas_client_deinitialize(int pid)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
- ma_client_s *client = ma_client_find_by_pid(pid);
- if (client) {
- ma_client_destroy(client);
- client = NULL;
- }
- return 0;
-}
-
-int CServiceMain::mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type)
+int CServiceMain::client_get_audio_format(pid_t pid, int* rate, int* channel, int* audio_type)
{
MAS_LOGD("[Enter] pid(%d)", pid);
}
#define MAX_LOCAL_VARIABLE_STRING_LEN 256
-int CServiceMain::mas_client_get_audio_source_type(int pid, char** type)
+int CServiceMain::client_get_audio_source_type(pid_t pid, char** type)
{
MAS_LOGD("[Enter] pid(%d)", pid);
return ret;
}
-int CServiceMain::mas_client_send_preprocessing_information(int pid)
+int CServiceMain::client_send_preprocessing_information(pid_t pid)
{
int ret = -1;
MAS_LOGD("[Enter] pid(%d)", pid);
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
- if (vconf_str) {
- ret = mServiceIpc.send_preprocessing_information(pid, vconf_str);
- free(vconf_str);
- vconf_str = NULL;
+ boost::optional<std::string> preprocessing_appid =
+ mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (preprocessing_appid) {
+ MAS_LOGD("preprocessing_assistant_appid : %s", (*preprocessing_appid).c_str());
+ ret = mServiceIpc.send_preprocessing_information(pid, (*preprocessing_appid).c_str());
}
return ret;
}
-int CServiceMain::mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status)
+int CServiceMain::client_send_voice_key_status_change(pid_t pid, ma_voice_key_status_e status)
{
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);
}
return ret;
}
-int CServiceMain::mas_client_activate(int pid)
-{
- int ret = -1;
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
-
- return ret;
-}
-
-int CServiceMain::mas_client_deactivate(int pid)
-{
- int ret = -1;
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE);
-
- return ret;
-}
-
-int CServiceMain::mas_client_send_asr_result(int pid, int event, char* asr_result)
+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);
return ret;
}
-int CServiceMain::mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json)
+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);
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<std::string> 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;
}
-int CServiceMain::mas_client_send_recognition_result(int pid, int result)
+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);
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<std::string> 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;
}
-int CServiceMain::mas_client_start_streaming_audio_data(int pid, int type)
+int CServiceMain::client_start_streaming_audio_data(pid_t pid, int type)
{
int ret = -1;
switch(type) {
case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
ret = mServicePlugin.start_streaming_utterance_data();
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED);
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED);
break;
case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
ret = mServicePlugin.start_streaming_previous_utterance_data();
break;
case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
ret = mServicePlugin.start_streaming_follow_up_data();
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED);
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED);
break;
}
return ret;
}
-int CServiceMain::mas_client_stop_streaming_audio_data(int pid, int type)
+int CServiceMain::client_stop_streaming_audio_data(pid_t pid, int type)
{
int ret = -1;
switch(type) {
return ret;
}
-int CServiceMain::mas_client_update_voice_feedback_state(int pid, int state)
+int CServiceMain::client_update_voice_feedback_state(pid_t 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<std::string> 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)
+int CServiceMain::client_set_assistant_specific_command(pid_t 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<std::string> 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)
+int CServiceMain::client_set_background_volume(pid_t 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<std::string> 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)
+int CServiceMain::client_set_preprocessing_allow_mode(pid_t 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<std::string> 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 (g_maclient_info[loop].used) {
- if (pid_appid && strncmp(pid_appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_maclient_info[loop].preprocessing_allow_mode = mode;
+ if (mClientInfo[loop].used) {
+ if (0 == pid_appid.compare(mClientInfo[loop].appid)) {
+ mClientInfo[loop].preprocessing_allow_mode = mode;
if (appid) {
- strncpy(g_maclient_info[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
- g_maclient_info[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
+ strncpy(mClientInfo[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
+ mClientInfo[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
} else {
- g_maclient_info[loop].preprocessing_allow_appid[0] = '\0';
+ mClientInfo[loop].preprocessing_allow_appid[0] = '\0';
}
}
}
}
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED);
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED);
return 0;
}
-int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result)
+int CServiceMain::client_send_preprocessing_result(pid_t 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<std::string> 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 (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = mClientInfo[mCurrentClientInfo].appid;
}
if (result) {
- MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
+ MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid.c_str());
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
} else {
MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
}
- ma_client_s* client = ma_client_find_by_appid(current_maclient_appid);
- if (client) {
- mServiceIpc.send_preprocessing_result(client->pid, result);
+ if (current_maclient_appid) {
+ pid_t pid_by_appid = mClientManager.find_client_pid_by_appid(
+ std::string{current_maclient_appid});
+ mServiceIpc.send_preprocessing_result(pid_by_appid, result);
}
return 0;
}
-int CServiceMain::mas_client_set_wake_word_audio_require_flag(int pid, bool require)
+int CServiceMain::client_set_wake_word_audio_require_flag(pid_t 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<std::string> 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)
+int CServiceMain::client_set_assistant_language(pid_t 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<std::string> 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)
+int CServiceMain::client_add_wake_word(pid_t 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<std::string> 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 (g_maclient_info[loop].used &&
- 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- ret = mServiceConfig.add_custom_wake_word(wake_word, language,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
+ if (mClientInfo[loop].used &&
+ 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,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
+ mServiceConfig.save_custom_wake_words(pid_appid.c_str(),
+ mClientInfo[loop].wakeup_word,
+ mClientInfo[loop].wakeup_language);
} else {
LOGE("add new wake word failed!");
return -1;
}
}
- 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)
+int CServiceMain::client_remove_wake_word(pid_t 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<std::string> 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 (g_maclient_info[loop].used &&
- 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- ret = mServiceConfig.remove_custom_wake_word(wake_word, language,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
+ if (mClientInfo[loop].used &&
+ 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,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
+ 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;
}
-int CServiceMain::mas_ui_client_initialize(int pid)
+int CServiceMain::ui_client_initialize(pid_t pid)
{
MAS_LOGD("[Enter] pid(%d)", pid);
return 0;
}
-int CServiceMain::mas_ui_client_deinitialize(int pid)
+int CServiceMain::ui_client_deinitialize(pid_t pid)
{
MAS_LOGD("[Enter] pid(%d)", pid);
return 0;
}
-int CServiceMain::mas_ui_client_change_assistant(const char* appid)
+int CServiceMain::ui_client_change_assistant(const char* appid)
{
MAS_LOGD("[Enter]");
return -1;
}
- bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
+ bool use_custom_ui = get_client_custom_ui_option_by_appid(appid);
mServiceIpc.masc_ui_dbus_enable_common_ui(!use_custom_ui);
- mas_set_current_client_by_appid(appid);
- int pid = mas_get_client_pid_by_appid(appid);
+ set_current_client_by_appid(appid);
+ pid_t pid = get_client_pid_by_appid(appid);
if (pid != -1) {
- mas_bring_client_to_foreground(appid);
- mas_client_send_preprocessing_information(pid);
+ bring_client_to_foreground(appid);
+ client_send_preprocessing_information(pid);
if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
- mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
+ client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
}
- mas_client_activate(pid);
+ 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();
// Appropriate MA Client not available, trying to launch new one
MAS_LOGD("MA Client with appid %s does not exist, launching client", (appid ? appid : "NULL"));
- /* The appid parameter might not exist after this function call, so we use appid string in our g_maclient_info */
+ /* The appid parameter might not exist after this function call, so we use appid string in our mClientInfo */
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- mas_launch_client_by_appid(g_maclient_info[loop].appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid) &&
+ 0 < strlen(mClientInfo[loop].wakeup_word[0])) {
+ if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ launch_client_by_appid(mClientInfo[loop].appid, CLIENT_LAUNCH_MODE_ACTIVATION);
}
}
}
return 0;
}
-static int mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) {
+static int assistant_info_cb(ma_assistant_info_s* info, void* user_data) {
int ret = -1;
CServiceMain* service_main = static_cast<CServiceMain*>(user_data);
if (service_main) {
}
int CServiceMain::add_assistant_info(ma_assistant_info_s* info) {
- MAS_LOGD("__mas_assistant_info_cb called");
+ MAS_LOGD("__assistant_info_cb called");
if (NULL == info) {
MAS_LOGE("info NULL, returning");
int index = -1;
int loop = 0;
while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) {
- if (false == g_maclient_info[loop].used) {
+ if (false == mClientInfo[loop].used) {
index = loop;
}
loop++;
}
if (-1 != index) {
- g_maclient_info[index].used = true;
- g_maclient_info[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
- g_maclient_info[index].preprocessing_allow_appid[0] = '\0';
+ mClientInfo[index].used = true;
+ mClientInfo[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
+ mClientInfo[index].preprocessing_allow_appid[0] = '\0';
MAS_LOGD("app_id(%s)", info->app_id);
- strncpy(g_maclient_info[index].appid, info->app_id, MAX_APPID_LEN);
- g_maclient_info[index].appid[MAX_APPID_LEN - 1] = '\0';
+ strncpy(mClientInfo[index].appid, info->app_id, MAX_APPID_LEN);
+ mClientInfo[index].appid[MAX_APPID_LEN - 1] = '\0';
- if (is_current_preprocessing_assistant(g_maclient_info[index].appid)) {
- g_current_preprocessing_maclient_info = index;
+ if (is_current_preprocessing_assistant(mClientInfo[index].appid)) {
+ mCurrentPreprocessingClientInfo = index;
}
for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
if (loop < info->cnt_wakeup && info->wakeup_list[loop]) {
MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, info->wakeup_list[loop], info->wakeup_language[loop]);
- strncpy(g_maclient_info[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN);
- g_maclient_info[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
+ strncpy(mClientInfo[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN);
+ mClientInfo[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
if (info->wakeup_language[loop]) {
- strncpy(g_maclient_info[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ strncpy(mClientInfo[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN);
+ mClientInfo[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
} else {
- strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ strncpy(mClientInfo[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
}
} else {
- strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
+ strncpy(mClientInfo[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
}
}
for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) {
if (loop < info->cnt_lang && info->supported_lang[loop]) {
MAS_LOGD("supported_lang(%d)(%s)", loop, info->supported_lang[loop]);
- strncpy(g_maclient_info[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ strncpy(mClientInfo[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN);
+ mClientInfo[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
} else {
- strncpy(g_maclient_info[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ strncpy(mClientInfo[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
}
}
MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine);
if (info->wakeup_engine) {
- strncpy(g_maclient_info[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN);
- g_maclient_info[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0';
+ strncpy(mClientInfo[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN);
+ mClientInfo[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0';
} else {
- g_maclient_info[index].wakeup_engine[0] = '\0';
+ mClientInfo[index].wakeup_engine[0] = '\0';
MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
}
- g_maclient_info[index].custom_ui_option = info->custom_ui_option;
+ mClientInfo[index].custom_ui_option = info->custom_ui_option;
MAS_LOGD("voice_key_support_mode(%d)", info->voice_key_support_mode);
- g_maclient_info[index].voice_key_support_mode = info->voice_key_support_mode;
+ mClientInfo[index].voice_key_support_mode = info->voice_key_support_mode;
MAS_LOGD("voice_key_tap_duration(%f)", info->voice_key_tap_duration);
- g_maclient_info[index].voice_key_tap_duration = info->voice_key_tap_duration;
+ mClientInfo[index].voice_key_tap_duration = info->voice_key_tap_duration;
+ MAS_LOGD("audio_processing_appid(%s)",
+ (info->audio_data_processing_appid ? (info->audio_data_processing_appid)->c_str() : "[NONE]"));
+ mClientInfo[index].audio_processing_appid = info->audio_data_processing_appid;
} else {
MAS_LOGD("Couldn't find an empty slot for storing assistant info");
}
- MAS_LOGD("__mas_assistant_info_cb end");
+ MAS_LOGD("__assistant_info_cb end");
return 0;
}
-static void active_state_changed_cb(keynode_t* key, void* data)
+static void active_state_changed_cb(std::string key, void* user_data)
{
- int vconf_value = 0;
- if (vconf_get_bool(MULTI_ASSISTANT_SETTINGS_ACTIVATED, &vconf_value) == 0) {
- MAS_LOGD("multi-assistant active state : %d\n", vconf_value);
+ IPreferenceManager* manager = static_cast<IPreferenceManager*>(user_data);
+ if (nullptr == manager) return;
+
+ boost::optional<bool> activated =
+ manager->get_bool(MULTI_ASSISTANT_SETTINGS_ACTIVATED);
+ if (activated) {
+ MAS_LOGD("multi-assistant active state : %d\n", *activated);
CServicePlugin *plugin = nullptr;
if (g_service_main) {
plugin = g_service_main->get_service_plugin();
}
if (plugin) {
- if (vconf_value) {
+ if (*activated) {
plugin->activate();
} else {
plugin->deactivate();
int CServiceMain::initialize_service_plugin(void)
{
+ MAS_LOGI("[ENTER]");
if (0 != mServicePlugin.initialize()) {
MAS_LOGE("Fail to ws intialize");
return -1;
}
- if (0 != mServicePlugin.set_language(g_current_lang.c_str())) {
+ if (0 != mServicePlugin.set_language(mCurrentLanguage.c_str())) {
MAS_LOGE("Fail to ws set language");
return -1;
}
- if (0 == mServiceConfig.get_assistant_info(mas_assistant_info_cb, this)) {
+ memset(&mClientInfo, 0x00, sizeof(mClientInfo));
+ mCurrentClientInfo = -1;
+ mCurrentPreprocessingClientInfo = -1;
+ mWakeupClientAppId.clear();
+
+ if (0 == mServiceConfig.get_assistant_info(assistant_info_cb, this)) {
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
int inner_loop;
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- mServiceConfig.load_custom_wake_words(g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_word, g_maclient_info[loop].wakeup_language);
- if (0 < strlen(g_maclient_info[loop].wakeup_engine)) {
+ if (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)) {
mServicePlugin.set_assistant_wakeup_engine(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_engine);
+ mClientInfo[loop].appid,
+ mClientInfo[loop].wakeup_engine);
}
for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) {
MAS_LOGD("Registering wakeup word %s for app %s",
- g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid);
+ mClientInfo[loop].wakeup_word[inner_loop], mClientInfo[loop].appid);
if (0 != mServicePlugin.add_assistant_wakeup_word(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_word[inner_loop],
- g_maclient_info[loop].wakeup_language[inner_loop])) {
+ mClientInfo[loop].appid,
+ mClientInfo[loop].wakeup_word[inner_loop],
+ mClientInfo[loop].wakeup_language[inner_loop])) {
MAS_LOGE("Fail to add assistant's wakeup word");
}
}
}
- for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) {
+ for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) {
+ if (0 < strlen(mClientInfo[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);
+ mClientInfo[loop].supported_language[inner_loop], mClientInfo[loop].appid);
if (0 != mServicePlugin.add_assistant_language(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].supported_language[inner_loop])) {
+ mClientInfo[loop].appid,
+ mClientInfo[loop].supported_language[inner_loop])) {
MAS_LOGE("Fail to add assistant's language");
}
}
int CServiceMain::process_activated_setting()
{
- if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, NULL)) {
+ if (mPreferenceManager.register_changed_callback(
+ MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, &mPreferenceManager)) {
/* Activate / deactivate according to the vconf key setting */
- active_state_changed_cb(NULL, NULL);
+ active_state_changed_cb(std::string{}, &mPreferenceManager);
} else {
#ifdef ENABLE_MULTI_ASSISTANT_BY_DEFAULT
/* Multi-assistant needs to be enabled by default, unless disabled explicitly */
const char *default_assistant = NULL;
if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
if (NULL == default_assistant) {
- if (g_maclient_info[0].used) {
- default_assistant = g_maclient_info[0].appid;
+ if (mClientInfo[0].used) {
+ default_assistant = mClientInfo[0].appid;
MAS_LOGW("No default assistant, setting %s as default", default_assistant);
mServicePlugin.set_default_assistant(default_assistant);
} else {
return 0;
}
-int CServiceMain::mas_get_current_client_pid()
+int CServiceMain::get_current_client_pid()
{
int ret = -1;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- const char *appid = g_maclient_info[g_current_maclient_info].appid;
- ma_client_s* client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+ const char *appid = mClientInfo[mCurrentClientInfo].appid;
+ if (appid) {
+ ret = mClientManager.find_client_pid_by_appid(std::string{appid});
}
}
return ret;
}
-int CServiceMain::mas_get_current_preprocessing_client_pid()
+pid_t CServiceMain::get_current_preprocessing_client_pid()
{
- int ret = -1;
- if (g_current_preprocessing_maclient_info >= 0 && g_current_preprocessing_maclient_info < MAX_MACLIENT_INFO_NUM) {
- const char *appid = g_maclient_info[g_current_preprocessing_maclient_info].appid;
- ma_client_s* client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
+ pid_t ret = -1;
+ if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < MAX_MACLIENT_INFO_NUM) {
+ const char *appid = mClientInfo[mCurrentPreprocessingClientInfo].appid;
+ if (appid) {
+ ret = mClientManager.find_client_pid_by_appid(std::string{appid});
}
}
return ret;
}
-int CServiceMain::mas_get_client_pid_by_appid(const char *appid)
+pid_t CServiceMain::get_current_audio_processing_pid()
{
- int ret = -1;
-
- if (appid) {
- ma_client_s *client = NULL;
- client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
+ pid_t ret = -1;
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+ boost::optional<std::string> audio_processing_appid =
+ mClientInfo[mCurrentClientInfo].audio_processing_appid;
+ if (audio_processing_appid) {
+ boost::optional<pid_t> audio_processing_pid;
+ audio_processing_pid = mApplicationManager.get_pid_by_appid((*audio_processing_appid).c_str());
+ if (audio_processing_pid) {
+ ret = *audio_processing_pid;
+ }
}
}
-
- 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);
- mas_client_deinitialize(ret);
- ret = -1;
- }
-
return ret;
}
-const char* CServiceMain::mas_get_client_appid_by_pid(int pid)
+pid_t CServiceMain::get_client_pid_by_appid(const char *appid)
{
- const char* ret = NULL;
+ pid_t ret = -1;
- ma_client_s *client = NULL;
- client = ma_client_find_by_pid(pid);
- if (client) {
- ret = client->appid;
+ if (appid) {
+ ret = mClientManager.find_client_pid_by_appid(std::string{appid});
}
- int status = aul_app_get_status_bypid(pid);
- if (NULL != ret && 0 > status) {
- MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
- pid, (ret ? ret : "NULL"), status);
- mas_client_deinitialize(pid);
- ret = NULL;
+ if (-1 != ret && !mApplicationManager.is_application_running(appid)) {
+ MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid, ret);
+ on_deinitialize(ret);
+ ret = -1;
}
return ret;
}
-bool CServiceMain::mas_get_client_custom_ui_option_by_appid(const char *appid)
+bool CServiceMain::get_client_custom_ui_option_by_appid(const char *appid)
{
bool ret = false;
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- ret = g_maclient_info[loop].custom_ui_option;
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid) &&
+ 0 < strlen(mClientInfo[loop].wakeup_word[0])) {
+ if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ ret = mClientInfo[loop].custom_ui_option;
}
}
}
return ret;
}
-int CServiceMain::mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
+int CServiceMain::get_client_pid_by_wakeup_word(const char *wakeup_word)
{
- const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- return mas_get_client_pid_by_appid(appid);
+ const char *appid = get_client_appid_by_wakeup_word(wakeup_word);
+ return get_client_pid_by_appid(appid);
}
-const char* CServiceMain::mas_get_client_appid_by_wakeup_word(const char *wakeup_word)
+const char* CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_word)
{
int loop;
const char *appid = NULL;
if (NULL == wakeup_word) return NULL;
for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid)) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
- appid = g_maclient_info[loop].appid;
+ if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) {
+ if (0 == strncmp(wakeup_word, mClientInfo[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ appid = mClientInfo[loop].appid;
}
}
}
/* Perform extended search, by eliminating blank characters */
if (NULL == appid) {
for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid)) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) {
char comparand[MAX_WAKEUP_WORD_LEN];
int comparand_index = 0;
for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
- if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
- comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
+ if (' ' != mClientInfo[loop].wakeup_word[inner_loop][index]) {
+ comparand[comparand_index++] = mClientInfo[loop].wakeup_word[inner_loop][index];
}
}
if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
- appid = g_maclient_info[loop].appid;
+ appid = mClientInfo[loop].appid;
}
}
}
return appid;
}
-int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word)
+int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
{
int loop;
int ret = -1;
- int prev_selection = g_current_maclient_info;
+ int prev_selection = mCurrentClientInfo;
for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid)) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
- g_current_maclient_info = loop;
+ if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) {
+ if (0 == strncmp(wakeup_word, mClientInfo[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ mCurrentClientInfo = loop;
ret = 0;
}
}
/* Perform extended search, by eliminating blank characters */
if (ret == -1) {
for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid)) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) {
char comparand[MAX_WAKEUP_WORD_LEN];
int comparand_index = 0;
for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
- if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
- comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
+ if (' ' != mClientInfo[loop].wakeup_word[inner_loop][index]) {
+ comparand[comparand_index++] = mClientInfo[loop].wakeup_word[inner_loop][index];
}
}
if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
- g_current_maclient_info = loop;
+ mCurrentClientInfo = loop;
ret = 0;
}
}
}
}
- if (g_current_maclient_info != prev_selection) {
+ if (mCurrentClientInfo != prev_selection) {
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
+ pid_t pid = get_client_pid_by_appid(mClientInfo[prev_selection].appid);
+ mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE);
}
}
return ret;
}
-int CServiceMain::mas_set_current_client_by_appid(const char *appid)
+int CServiceMain::set_current_client_by_appid(const char *appid)
{
int ret = -1;
- int prev_selection = g_current_maclient_info;
+ int prev_selection = mCurrentClientInfo;
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_current_maclient_info = loop;
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid) &&
+ 0 < strlen(mClientInfo[loop].wakeup_word[0])) {
+ if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ mCurrentClientInfo = loop;
ret = 0;
}
}
}
- if (g_current_maclient_info != prev_selection) {
+ if (mCurrentClientInfo != prev_selection) {
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
+ pid_t pid = get_client_pid_by_appid(mClientInfo[prev_selection].appid);
+ mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE);
}
}
return ret;
}
-int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode)
+int CServiceMain::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) {
bool found = false;
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_wakeup_maclient_appid = g_maclient_info[loop].appid;
+ if (mClientInfo[loop].used &&
+ 0 < strlen(mClientInfo[loop].appid)) {
+ if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ mWakeupClientAppId = mClientInfo[loop].appid;
found = true;
}
}
}
- MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid.c_str(), found);
+ 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)
+int CServiceMain::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)
+int CServiceMain::launch_client_by_wakeup_word(const char *wakeup_word)
{
- const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- return mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ const char *appid = get_client_appid_by_wakeup_word(wakeup_word);
+ return launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
}
-int CServiceMain::mas_prelaunch_default_assistant()
+int CServiceMain::prelaunch_default_assistant()
{
/* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
- int prelaunch_mode;
- int res = vconf_get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE, &prelaunch_mode);
- if (0 == res && 0 != prelaunch_mode) {
+ boost::optional<bool> prelaunch_mode =
+ mPreferenceManager.get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE);
+ 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 (default_assistant &&
+ !(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);
+ launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH);
}
}
}
return 0;
}
-int CServiceMain::mas_update_voice_key_support_mode()
+int CServiceMain::update_voice_key_support_mode()
{
/* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
bool successful = false;
const char *default_assistant = NULL;
if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used) {
+ if (mClientInfo[loop].used) {
if (default_assistant &&
- strncmp(default_assistant, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- float duration = g_maclient_info[loop].voice_key_tap_duration;
+ strncmp(default_assistant, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ float duration = mClientInfo[loop].voice_key_tap_duration;
if (0.0f < duration) {
mServicePlugin.set_voice_key_tap_duration(duration);
} else {
mServicePlugin.unset_voice_key_tap_duration();
}
mServicePlugin.set_voice_key_support_mode(
- g_maclient_info[loop].voice_key_support_mode);
+ mClientInfo[loop].voice_key_support_mode);
successful = true;
}
}
ma_preprocessing_allow_mode_e CServiceMain::get_preprocessing_allow_mode(const char* appid)
{
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (appid && g_maclient_info[loop].used) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- return g_maclient_info[loop].preprocessing_allow_mode;
+ if (appid && mClientInfo[loop].used) {
+ if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) {
+ return mClientInfo[loop].preprocessing_allow_mode;
}
}
}
/* This might need to be read from settings in the future, but using macro for now */
//#define BRING_PREPROCESSING_ASSISTANT_TO_FRONT
-int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
+int CServiceMain::process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
{
const char* current_maclient_appid = NULL;
const char* preprocessing_allow_appid = NULL;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
- preprocessing_allow_appid = g_maclient_info[g_current_maclient_info].preprocessing_allow_appid;
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = mClientInfo[mCurrentClientInfo].appid;
+ preprocessing_allow_appid = mClientInfo[mCurrentClientInfo].preprocessing_allow_appid;
}
ma_preprocessing_allow_mode_e mode = get_preprocessing_allow_mode(current_maclient_appid);
#ifndef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
/* If there is no need to bring preprocessing assistant to front,
current_maclient should always be brought to front */
- mas_bring_client_to_foreground(current_maclient_appid);
+ bring_client_to_foreground(current_maclient_appid);
#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
if (check_preprocessing_assistant_exists()) {
if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
MA_PREPROCESSING_ALLOW_ALL == mode) {
if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
}
}
} else {
#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
/* If preprocessing assistant does not exist, there is no way to enable
preprocessing assistant, so bring current maclient to front right away */
- mas_bring_client_to_foreground(current_maclient_appid);
+ bring_client_to_foreground(current_maclient_appid);
#endif
}
}
break;
case PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED:
{
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
/* Enable preprocessing mode only if the preprocessing assistant exists */
if (check_preprocessing_assistant_exists()) {
if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
MA_PREPROCESSING_ALLOW_ALL == mode) {
if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
}
}
}
break;
case PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED:
{
- if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED == g_current_preprocessing_state) {
- g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE;
- } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == g_current_preprocessing_state) {
+ if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED == mCurrentPreprocessingState) {
+ mCurrentPreprocessingState = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE;
+ } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == mCurrentPreprocessingState) {
/* If preprocessing assistant does not exist, the current_maclient
would have been brought to front already on wakeup event */
#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
if (check_preprocessing_assistant_exists()) {
- mas_bring_client_to_foreground(current_maclient_appid);
+ bring_client_to_foreground(current_maclient_appid);
}
#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_NONE;
}
}
break;
case PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED:
{
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_NONE;
if (check_preprocessing_assistant_exists()) {
if (MA_PREPROCESSING_ALLOW_FOLLOW_UP == mode ||
MA_PREPROCESSING_ALLOW_ALL == mode) {
- g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP;
}
}
}
case PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED:
{
#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
- PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
- if (vconf_str) {
- mas_bring_client_to_foreground(vconf_str);
- free(vconf_str);
- vconf_str = NULL;
+ if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == mCurrentPreprocessingState ||
+ PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == mCurrentPreprocessingState) {
+ boost::optional<std::string> preprocessing_assistant =
+ mPreferenceManager.get_bool(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (preprocessing_assistant) {
+ MAS_LOGD("preprocessing_assistant_appid : %s", (*preprocessing_assistant).c_str());
+ bring_client_to_foreground((*preprocessing_assistant).c_str());
}
}
#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_NONE;
}
break;
case PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED:
{
#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
- PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
- mas_bring_client_to_foreground(current_maclient_appid);
+ if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == mCurrentPreprocessingState ||
+ PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == mCurrentPreprocessingState) {
+ bring_client_to_foreground(current_maclient_appid);
}
#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ mCurrentPreprocessingState = PREPROCESSING_STATE_NONE;
}
break;
}
return 0;
}
-int CServiceMain::mas_set_current_service_state(ma_service_state_e state)
+int CServiceMain::set_current_service_state(ma_service_state_e state)
{
- g_current_service_state = state;
-
- ma_client_s *data = NULL;
+ mCurrentServiceState = state;
- int count = g_slist_length(g_client_list);
+ int count = mClientManager.get_client_num();
int i;
for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
+ pid_t pid = mClientManager.find_client_pid_by_index(i);
- if (NULL != data && -1 != data->pid) {
- int ret = mServiceIpc.service_state_change(data->pid, state);
+ if (-1 != pid) {
+ int ret = mServiceIpc.change_service_state(pid, state);
if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send wakeup service state change to %d, ret(%d)",
- data->pid, ret);
+ MAS_LOGE("[ERROR] Fail to set service state change to %d, ret(%d)", pid, ret);
}
}
}
return 0;
}
-ma_service_state_e CServiceMain::mas_get_current_service_state()
+ma_service_state_e CServiceMain::get_current_service_state()
{
- return g_current_service_state;
+ return mCurrentServiceState;
}
bool CServiceMain::is_valid_wakeup_engine(const char* appid)
{
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)) {
+ if (mClientInfo[loop].used) {
+ LOGD("comparing appid : %s %s", mClientInfo[loop].wakeup_engine, appid);
+ if (0 == strncmp(mClientInfo[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
return true;
}
}
return false;
}
-int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+bool CServiceMain::is_wakeup_engine(const pkgmgrinfo_appinfo_h handle)
{
- if (nullptr == g_service_main) return -1;
+ if (nullptr == g_service_main) return false;
+ 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) {
- bool exists = g_service_main->is_valid_wakeup_engine(appid);
- if (exists) {
- *result = 1;
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
+ if (mClientInfo[loop].used) {
+ LOGD("comparing appid : %s %s", mClientInfo[loop].wakeup_engine, appid);
+ if (0 == strncmp(mClientInfo[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
+ is_wakeup_engine = true;
+ }
}
}
} else {
LOGE("pkgmgrinfo_appinfo_get_appid failed! error code=%d", ret);
}
+ return is_wakeup_engine;
+}
+
+bool CServiceMain::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)
+{
+ if (!g_service_main) return 0;
+
+ int *result = (int*)user_data;
+ if (result) {
+ if (g_service_main->is_voice_assistant(handle)) {
+ *result = 1;
+ } else if (g_service_main->is_wakeup_engine(handle)) {
+ *result = 1;
+ }
+ }
return 0;
}
pkgmgrinfo_pkginfo_h handle = NULL;
static bool in_progress = false;
bool should_exit = false;
+ bool pkginfo_found = true;
if (!package || !type)
return;
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;
type, package, event_type, event_state, progress, error);
ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &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(\"%s\",~) returned %d", package, ret);
/* Try to get in user packages */
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());
- return;
+ MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ());
+ 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) {
MAS_LOGE("service_main is NULL");
}
}
- } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) {
- MAS_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) {
+ MAS_LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED/FAILED event : %d %d",
+ event_state, event_type);
if (false == in_progress) {
if (service_main) {
service_main->deinitialize_service_plugin();
}
}
- 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");
bool CServiceMain::app_create(void *data)
{
// Todo: add your code here.
- MAS_LOGD("[Enter] Service app create");
+ MAS_LOGI("[ENTER] Service app create");
g_service_main = this;
- mServiceIpc.set_service_main(this);
+ mClientManager.set_application_manager(&mApplicationManager);
+
+ mServiceIpc.set_client_manager(&mClientManager);
+ mServiceIpc.set_application_manager(&mApplicationManager);
+ mServiceIpc.set_service_ipc_observer(this);
mServicePlugin.set_service_ipc(&mServiceIpc);
mServicePlugin.set_service_main(this);
process_activated_setting();
- mas_prelaunch_default_assistant();
- mas_update_voice_key_support_mode();
+ prelaunch_default_assistant();
+ update_voice_key_support_mode();
/* For the case of preprocessing assistant, it always have to be launched beforehand */
- char *vconf_str;
- vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
- MAS_LOGD("prelaunching preprocessing_assistant_appid : %s", vconf_str);
- mas_launch_client_by_appid(vconf_str, CLIENT_LAUNCH_MODE_PRELAUNCH);
- free(vconf_str);
- vconf_str = NULL;
+ boost::optional<std::string> preprocessing_assistant =
+ mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (preprocessing_assistant) {
+ MAS_LOGD("prelaunching preprocessing_assistant_appid : %s", (*preprocessing_assistant).c_str());
+ launch_client_by_appid((*preprocessing_assistant).c_str(), CLIENT_LAUNCH_MODE_PRELAUNCH);
}
- if (!g_pkgmgr) {
- int ret = package_manager_create(&g_pkgmgr);
+ if (!mPackageManagerHandle) {
+ int ret = package_manager_create(&mPackageManagerHandle);
if (ret == PACKAGE_MANAGER_ERROR_NONE) {
- ret = package_manager_set_event_cb(g_pkgmgr, _package_manager_event_cb, this);
+ ret = package_manager_set_event_cb(mPackageManagerHandle, _package_manager_event_cb, this);
if (ret == PACKAGE_MANAGER_ERROR_NONE) {
LOGD("package_manager_set_event_cb succeeded.");
} else {
}
}
+ MAS_LOGI("[END] Service app create");
return true;
}
void CServiceMain::app_terminate(void *data)
{
MAS_LOGI("[ENTER]");
- if (g_pkgmgr) {
- package_manager_unset_event_cb(g_pkgmgr);
- package_manager_destroy(g_pkgmgr);
- g_pkgmgr = NULL;
+ if (mPackageManagerHandle) {
+ package_manager_unset_event_cb(mPackageManagerHandle);
+ package_manager_destroy(mPackageManagerHandle);
+ mPackageManagerHandle = NULL;
}
deinitialize_service_plugin();
- vconf_ignore_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb);
+ mPreferenceManager.unregister_changed_callback(
+ MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb);
int ret = mServiceIpc.close_connection();
if (0 != ret) {
return;
}
+int CServiceMain::on_initialize(pid_t pid) {
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ std::string pid_appid;
+ boost::optional<std::string> 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(pid_appid.c_str());
+
+ /* And remove a client that has same pid also */
+ mClientManager.destroy_client_by_pid(pid);
+
+ mClientManager.create_client(pid, pid_appid.c_str());
+
+ const char *current_maclient_appid = NULL;
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = mClientInfo[mCurrentClientInfo].appid;
+ }
+
+ client_send_preprocessing_information(pid);
+ if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
+ client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
+ }
+ if (current_maclient_appid && 0 == pid_appid.compare(current_maclient_appid)) {
+ MAS_LOGD("MA client with current maclient appid connected!");
+
+ if (0 == mWakeupClientAppId.compare(pid_appid)) {
+ mWakeupClientAppId.clear();
+ mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_ACTIVE);
+ process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
+ } else {
+ MAS_LOGE("[ERROR] mWakeupClientAppId and appid differ : %s %s",
+ mWakeupClientAppId.c_str(), pid_appid.c_str());
+ }
+ } else {
+ MAS_LOGD("MA client connected, but its appid does not match with current maclient");
+ }
+
+ mServiceIpc.change_service_state(pid, get_current_service_state());
+ } else {
+ MAS_LOGE("[ERROR] Fail to retrieve appid");
+ }
+
+ return 0;
+}
+
+int CServiceMain::on_deinitialize(pid_t pid) {
+ MAS_LOGD("[Enter] pid(%d)", pid);
+ mClientManager.destroy_client_by_pid(pid);
+ return 0;
+}
+
+int CServiceMain::on_get_audio_format(pid_t pid, int& rate, int& channel, int& audio_type) {
+ int main_rate, main_channel, main_audio_type;
+ int ret = client_get_audio_format(pid,
+ &main_rate, &main_channel, &main_audio_type);
+ rate = main_rate;
+ channel = main_channel;
+ audio_type = main_audio_type;
+ return ret;
+}
+
+int CServiceMain::on_get_audio_source_type(pid_t pid, std::string& type) {
+ char *main_type = nullptr;
+ int ret = client_get_audio_source_type(pid, &main_type);
+ if (0 == ret && main_type) {
+ type = std::string{main_type};
+ }
+ return ret;
+}
+
+int CServiceMain::on_send_asr_result(pid_t pid, int event, std::string asr_result) {
+ return client_send_asr_result(pid, event, asr_result.c_str());
+}
+
+int CServiceMain::on_send_result(pid_t pid, std::string display_text,
+ std::string utterance_text, std::string result_json) {
+ return client_send_result(pid,
+ display_text.c_str(), utterance_text.c_str(), result_json.c_str());
+}
+
+int CServiceMain::on_send_recognition_result(pid_t pid, int result) {
+ return client_send_recognition_result(pid, result);
+}
+
+int CServiceMain::on_start_streaming_audio_data(pid_t pid, int type) {
+ return client_start_streaming_audio_data(pid, type);
+}
+
+int CServiceMain::on_stop_streaming_audio_data(pid_t pid, int type) {
+ return client_stop_streaming_audio_data(pid, type);
+}
+
+int CServiceMain::on_update_voice_feedback_state(pid_t pid, int state) {
+ return client_update_voice_feedback_state(pid, state);
+}
+
+int CServiceMain::on_send_assistant_specific_command(pid_t pid, std::string command) {
+ return client_set_assistant_specific_command(pid, command.c_str());
+}
+
+int CServiceMain::on_set_background_volume(pid_t pid, double ratio) {
+ return client_set_background_volume(pid, ratio);
+}
+
+int CServiceMain::on_set_preprocessing_allow_mode(pid_t pid, int mode, std::string app_id) {
+ return client_set_preprocessing_allow_mode(pid,
+ static_cast<ma_preprocessing_allow_mode_e>(mode), app_id.c_str());
+}
+
+int CServiceMain::on_send_preprocessing_result(pid_t pid, int result) {
+ return client_send_preprocessing_result(pid, result);
+}
+
+int CServiceMain::on_set_wake_word_audio_require_flag(pid_t pid, int require) {
+ return client_set_wake_word_audio_require_flag(pid, require);
+}
+
+int CServiceMain::on_set_assistant_language(pid_t pid, std::string language) {
+ return client_set_assistant_language(pid, language.c_str());
+}
+
+int CServiceMain::on_add_wake_word(pid_t pid, std::string wake_word, std::string language) {
+ return client_add_wake_word(pid, wake_word.c_str(), language.c_str());
+}
+
+int CServiceMain::on_remove_wake_word(pid_t pid, std::string wake_word, std::string language) {
+ return client_remove_wake_word(pid, wake_word.c_str(), language.c_str());
+}
+
+int CServiceMain::on_ui_initialize(pid_t pid)
+{
+ return ui_client_initialize(pid);
+}
+
+int CServiceMain::on_ui_deinitialize(pid_t pid)
+{
+ return ui_client_deinitialize(pid);
+}
+
+int CServiceMain::on_ui_change_assistant(std::string app_id)
+{
+ return ui_client_change_assistant(app_id.c_str());
+}