diff --git a/src/base/LaunchPoint.h b/src/base/LaunchPoint.h index 9845d65..44cf1ba 100644 --- a/src/base/LaunchPoint.h +++ b/src/base/LaunchPoint.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2019 LG Electronics, Inc. +// Copyright (c) 2012-2020 LG Electronics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ #include #include "base/AppDescription.h" -#include "base/LunaTask.h" #include "util/JValueUtil.h" using namespace std; @@ -154,23 +153,13 @@ friend class LaunchPointList; return largeIcon; } - const JValue getParams(LunaTaskPtr lunaTask) const + JValue getParams() const { - JValue paramsInRequest = lunaTask->getParams().duplicate(); - JValue paramsInDatabase = pbnjson::Object(); - int displayAffinity = -1; - - JValueUtil::getValue(m_database, "params", paramsInDatabase); - paramsInDatabase = paramsInDatabase.duplicate(); - - if (paramsInRequest.objectSize() == 0) { - return paramsInDatabase; - } else if (paramsInRequest.objectSize() == 1 && - JValueUtil::getValue(paramsInRequest, "displayAffinity", displayAffinity)) { - paramsInDatabase.put("displayAffinity", displayAffinity); - return paramsInDatabase; + JValue params; + if (JValueUtil::getValue(m_database, "params", params)) { + return params.duplicate(); } else { - return paramsInRequest; + return pbnjson::Object(); } } diff --git a/src/base/LaunchPointList.cpp b/src/base/LaunchPointList.cpp index 093a30f..a0398dc 100644 --- a/src/base/LaunchPointList.cpp +++ b/src/base/LaunchPointList.cpp @@ -79,12 +79,10 @@ LaunchPointPtr LaunchPointList::getByLunaTask(LunaTaskPtr lunaTask) if (lunaTask == nullptr) return nullptr; - return getByIds(lunaTask->getLaunchPointId(), lunaTask->getAppId()); -} - -LaunchPointPtr LaunchPointList::getByIds(const string& launchPointId, const string& appId) -{ LaunchPointPtr launchPoint = nullptr; + const string& launchPointId = lunaTask->getLaunchPointId(); + const string& appId = lunaTask->getAppId(); + if (!launchPointId.empty()) launchPoint = getByLaunchPointId(launchPointId); else if (!appId.empty()) diff --git a/src/base/LaunchPointList.h b/src/base/LaunchPointList.h index 5ad1e79..c711b5e 100644 --- a/src/base/LaunchPointList.h +++ b/src/base/LaunchPointList.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019 LG Electronics, Inc. +// Copyright (c) 2019-2020 LG Electronics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,7 +41,6 @@ friend class ISingleton; LaunchPointPtr createDefault(AppDescriptionPtr appDesc); LaunchPointPtr getByLunaTask(LunaTaskPtr lunaTask); - LaunchPointPtr getByIds(const string& launchPointId, const string& appId); LaunchPointPtr getByAppId(const string& appId); LaunchPointPtr getByLaunchPointId(const string& launchPointId); diff --git a/src/base/LunaTask.h b/src/base/LunaTask.h index c761055..43664f5 100644 --- a/src/base/LunaTask.h +++ b/src/base/LunaTask.h @@ -132,10 +132,14 @@ friend class LunaTaskList; JValue getParams() { if (m_requestPayload.hasKey("params")) - return m_requestPayload["params"]; + return m_requestPayload["params"].duplicate(); else return pbnjson::Object(); } + void setParams(JValue params) + { + m_requestPayload.put("params", params.duplicate()); + } void setErrCodeAndText(int errorCode, string errorText) { diff --git a/src/base/RunningAppList.cpp b/src/base/RunningAppList.cpp index 978680c..0b0aa30 100644 --- a/src/base/RunningAppList.cpp +++ b/src/base/RunningAppList.cpp @@ -109,14 +109,22 @@ RunningAppPtr RunningAppList::getByLunaTask(LunaTaskPtr lunaTask) string instanceId = lunaTask->getInstanceId(); int displayId = lunaTask->getDisplayId(); + LaunchPointPtr launchPoint = LaunchPointList::getInstance().getByLaunchPointId(launchPointId); + if (launchPoint && appId.empty()) { + appId = launchPoint->getAppId(); + } + // TODO Currently, only webOS auto supports multiple instances (same appId at once on other displays) // Following lines should be modified after WAM supports - if (strcmp(WEBOS_TARGET_DISTRO, "webos-auto") != 0) - displayId = -1; + RunningAppPtr runningApp = nullptr; + if (strcmp(WEBOS_TARGET_DISTRO, "webos-auto") != 0) { + runningApp = getByIds(instanceId, appId, -1); + } else { + runningApp = getByIds(instanceId, appId, displayId); + } - // Normally, clients doesn't provide all information about running application + // Normally, lunaTask doesn't have all information about running application // However, SAM needs all information internally during managing application lifecycle. - RunningAppPtr runningApp = getByIds(instanceId, launchPointId, appId, displayId); if (runningApp) { lunaTask->setInstanceId(runningApp->getInstanceId()); lunaTask->setLaunchPointId(runningApp->getLaunchPointId()); @@ -133,13 +141,11 @@ RunningAppPtr RunningAppList::getByLunaTask(LunaTaskPtr lunaTask) return runningApp; } -RunningAppPtr RunningAppList::getByIds(const string& instanceId, const string& launchPointId, const string& appId, const int displayId) +RunningAppPtr RunningAppList::getByIds(const string& instanceId, const string& appId, const int displayId) { RunningAppPtr runningApp = nullptr; if (!instanceId.empty()) runningApp = getByInstanceId(instanceId); - else if (!launchPointId.empty()) - runningApp = getByLaunchPointId(launchPointId, displayId); else if (!appId.empty()) runningApp = getByAppId(appId, displayId); @@ -148,8 +154,6 @@ RunningAppPtr RunningAppList::getByIds(const string& instanceId, const string& l if (!instanceId.empty() && instanceId != runningApp->getInstanceId()) return nullptr; - if (!launchPointId.empty() && launchPointId != runningApp->getLaunchPointId()) - return nullptr; if (!appId.empty() && appId != runningApp->getAppId()) return nullptr; if (displayId != -1 && displayId != runningApp->getDisplayId()) @@ -177,19 +181,6 @@ RunningAppPtr RunningAppList::getByToken(const LSMessageToken& token) return nullptr; } -RunningAppPtr RunningAppList::getByLaunchPointId(const string& launchPointId, const int displayId) -{ - for (auto it = m_map.begin(); it != m_map.end(); ++it) { - if ((*it).second->getLaunchPointId() == launchPointId) { - if (displayId == -1) - return it->second; - if ((*it).second->getDisplayId() == displayId) - return it->second; - } - } - return nullptr; -} - RunningAppPtr RunningAppList::getByAppId(const string& appId, const int displayId) { for (auto it = m_map.begin(); it != m_map.end(); ++it) { diff --git a/src/base/RunningAppList.h b/src/base/RunningAppList.h index 11085be..756ce99 100644 --- a/src/base/RunningAppList.h +++ b/src/base/RunningAppList.h @@ -39,10 +39,9 @@ friend class ISingleton; RunningAppPtr createByLaunchPointId(const string& launchPointId); RunningAppPtr getByLunaTask(LunaTaskPtr lunaTask); - RunningAppPtr getByIds(const string& instanceId, const string& launchPointId, const string& appId, const int displayId = -1); + RunningAppPtr getByIds(const string& instanceId, const string& appId, const int displayId = -1); RunningAppPtr getByInstanceId(const string& instanceId); RunningAppPtr getByToken(const LSMessageToken& token); - RunningAppPtr getByLaunchPointId(const string& launchPointId, const int displayId = -1); RunningAppPtr getByAppId(const string& appId, const int displayId = -1); RunningAppPtr getByPid(const pid_t pid); RunningAppPtr getByWebprocessid(const string& webprocessid); diff --git a/src/bus/client/NativeContainer.cpp b/src/bus/client/NativeContainer.cpp index 680f91b..7092d3c 100644 --- a/src/bus/client/NativeContainer.cpp +++ b/src/bus/client/NativeContainer.cpp @@ -98,7 +98,7 @@ void NativeContainer::launch(RunningAppPtr runningApp, LunaTaskPtr lunaTask) params.put("appId", runningApp->getLaunchPoint()->getAppDesc()->getAppId()); params.put("params", lunaTask->getParams()); } else { - params = runningApp->getLaunchPoint()->getParams(lunaTask); + params = lunaTask->getParams(); params.put("event", "launch"); params.put("reason", lunaTask->getReason()); params.put("appId", lunaTask->getAppId()); diff --git a/src/bus/client/WAM.cpp b/src/bus/client/WAM.cpp index b1a14bf..565a99f 100644 --- a/src/bus/client/WAM.cpp +++ b/src/bus/client/WAM.cpp @@ -49,7 +49,7 @@ bool WAM::onListRunningApps(LSHandle* sh, LSMessage* message, void* context) displayId = RunningApp::getDisplayId(instanceId); } - RunningAppPtr runningApp = RunningAppList::getInstance().getByIds(instanceId, "", appId); + RunningAppPtr runningApp = RunningAppList::getInstance().getByIds(instanceId, appId); if (runningApp == nullptr) { Logger::warning(getInstance().getClassName(), __FUNCTION__, Logger::format("SAM might be restarted. RunningApp is created by WAM: appId(%s) instanceId(%s)", appId.c_str(), instanceId.c_str())); @@ -183,7 +183,7 @@ void WAM::launch(RunningAppPtr runningApp, LunaTaskPtr lunaTask) requestPayload.put("reason", lunaTask->getReason()); requestPayload.put("launchingAppId", lunaTask->getCaller()); requestPayload.put("launchingProcId", ""); - requestPayload.put("parameters", runningApp->getLaunchPoint()->getParams(lunaTask)); + requestPayload.put("parameters", lunaTask->getParams()); if (runningApp->isKeepAlive()) { requestPayload.put("keepAlive", true); diff --git a/src/bus/service/ApplicationManager.cpp b/src/bus/service/ApplicationManager.cpp index 63f7013..2ec36df 100644 --- a/src/bus/service/ApplicationManager.cpp +++ b/src/bus/service/ApplicationManager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2019 LG Electronics, Inc. +// Copyright (c) 2017-2020 LG Electronics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -239,6 +239,22 @@ void ApplicationManager::detach() void ApplicationManager::launch(LunaTaskPtr lunaTask) { + LaunchPointPtr launchPoint = LaunchPointList::getInstance().getByLunaTask(lunaTask); + + // Load params from DB or appinfo.json + JValue params = lunaTask->getParams(); + int displayAffinity = -1; + // launchPoint can be nullptr because there is only 'instanceId' in requestPayload + if (launchPoint) { + if (launchPoint && params.objectSize() == 0) { + lunaTask->setParams(launchPoint->getParams()); + } else if (params.objectSize() == 1 && JValueUtil::getValue(params, "displayAffinity", displayAffinity)) { + params = launchPoint->getParams(); + params.put("displayAffinity", displayAffinity); + lunaTask->setParams(params); + } + } + RunningAppPtr runningApp = RunningAppList::getInstance().getByLunaTask(lunaTask); if (runningApp != nullptr) { PolicyManager::getInstance().relaunch(lunaTask); diff --git a/src/bus/service/ApplicationManager.h b/src/bus/service/ApplicationManager.h index b9bbfbb..bd27f0f 100644 --- a/src/bus/service/ApplicationManager.h +++ b/src/bus/service/ApplicationManager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2019 LG Electronics, Inc. +// Copyright (c) 2017-2020 LG Electronics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/conf/RuntimeInfo.cpp b/src/conf/RuntimeInfo.cpp index 1eacf26..a7128b3 100644 --- a/src/conf/RuntimeInfo.cpp +++ b/src/conf/RuntimeInfo.cpp @@ -31,13 +31,13 @@ RuntimeInfo::~RuntimeInfo() void RuntimeInfo::initialize() { - string displayId = getenv("DISPLAY_ID"); - string container = getenv("container"); + char* displayId = getenv("DISPLAY_ID"); + char* container = getenv("container"); - if (!displayId.empty()) { - m_displayId = stoi(displayId.c_str()); + if (displayId != nullptr) { + m_displayId = stoi(displayId); } - if (!container.empty()) { + if (container != nullptr) { m_isInContainer = true; } Logger::info(getClassName(), __FUNCTION__, Logger::format("DisplayId(%d) IsInContainer(%s)", m_displayId, Logger::toString(m_isInContainer))); diff --git a/src/conf/RuntimeInfo.h b/src/conf/RuntimeInfo.h index aad381e..37a4b89 100644 --- a/src/conf/RuntimeInfo.h +++ b/src/conf/RuntimeInfo.h @@ -49,10 +49,11 @@ friend class ISingleton ; bool isInContainer() { - return m_isInContainer; + return false; + // TODO this should be enabled to support multiple profiles + // return m_isInContainer; } - private: RuntimeInfo();