#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>
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;
}
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_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<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)
{
- 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)
{
- 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)
{
- 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 (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);
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<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 (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
}
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);
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<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)
{
- 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)
{
- 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 (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 {
}
}
- 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<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 (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;
}
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;
}
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) {
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)
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);
}
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<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(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) {
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");