while (NULL != (dir = readdir(d))) {
if (suffix && strlen(suffix) <= strlen(dir->d_name)) {
if (0 == strcmp(dir->d_name + strlen(dir->d_name) - strlen(suffix), suffix)) {
- char fullpath[_POSIX_PATH_MAX];
- snprintf(fullpath, _POSIX_PATH_MAX - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
+ const size_t path_max = _POSIX_PATH_MAX * 2;
+ char fullpath[path_max];
+ snprintf(fullpath, path_max - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
MAS_LOGI("Parsing file : %s\n", fullpath);
parse_assistant_info(callback, fullpath, user_data);
}
#include <string.h>
#include <glib.h>
+#include <chrono>
+#include <ctime>
+#include <list>
+#include <sstream>
+#include <tuple>
+
#include "service_common.h"
#include "service_main.h"
#include "service_plugin.h"
int CServiceMain::client_set_background_volume(pid_t pid, double ratio)
{
- if (!is_current_assistant(pid)) return -1;
+ bool valid = is_current_assistant(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;
}
+
+ /* Better extracting this into a new Ducking Management class */
+ const int max_history_size = 5;
+ static std::list<std::tuple<pid_t, std::string, double, std::time_t, bool>> history;
+ history.push_front(std::make_tuple(pid, pid_appid, ratio,
+ std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()), valid));
+ if (history.size() > max_history_size) history.pop_back();
+
+ std::stringstream ss;
+ for (auto item : history) {
+ std::time_t time_info = std::get<3>(item);
+ char time_string[32];
+ std::strftime(time_string, sizeof(time_string), "%H%M%S", std::localtime(&time_info));
+ ss << "[";
+ ss << std::get<0>(item);
+ ss << ",";
+ ss << std::get<1>(item);
+ ss << ",";
+ ss << std::get<2>(item);
+ ss << ",";
+ ss << time_string;
+ ss << ",";
+ ss << std::get<4>(item);
+ ss << "]";
+ }
+ MAS_LOGW("History : %s", ss.str().c_str());
+
+ if (!valid) return -1;
+
+ if (ratio < 1.0f) {
+ mLastDuckingRequester = pid;
+ } else {
+ mLastDuckingRequester = -1;
+ }
+
mServicePlugin.set_background_volume(pid_appid.c_str(), ratio);
return 0;
}
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
pid_t pid = get_client_pid_by_appid(items[prev_selection].appid);
mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE);
+ if (mLastDuckingRequester == pid) {
+ MAS_LOGE("Last ducking requester is deactivated, resetting background volume");
+ mServicePlugin.set_background_volume(items[prev_selection].appid, 1.0f);
+ mLastDuckingRequester = -1;
+ }
}
}
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
pid_t pid = get_client_pid_by_appid(items[prev_selection].appid);
mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE);
+ if (mLastDuckingRequester == pid) {
+ MAS_LOGE("Last ducking requester is deactivated, resetting background volume");
+ mServicePlugin.set_background_volume(items[prev_selection].appid, 1.0f);
+ mLastDuckingRequester = -1;
+ }
}
}
int CServiceMain::on_deinitialize(pid_t pid) {
MAS_LOGD("[Enter] pid(%d)", pid);
+ if (mLastDuckingRequester == pid) {
+ MAS_LOGE("Last ducking requester has disconnected, resetting background volume");
+ std::string pid_appid = mClientManager.find_client_appid_by_pid( pid);
+ mServicePlugin.set_background_volume(pid_appid.c_str(), 1.0f);
+ mLastDuckingRequester = -1;
+ }
+
mClientManager.destroy_client_by_pid(pid);
+
return 0;
}