Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Change-Id: I750d798641fb245dcafcba96a5e98dff10350566
  • Loading branch information
sangwoo-kang committed Mar 17, 2020
2 parents f98949b + c821e45 commit 8a1443b
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 61 deletions.
23 changes: 6 additions & 17 deletions src/base/LaunchPoint.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +25,6 @@
#include <string>

#include "base/AppDescription.h"
#include "base/LunaTask.h"
#include "util/JValueUtil.h"

using namespace std;
Expand Down Expand Up @@ -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();
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/base/LaunchPointList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions src/base/LaunchPointList.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,7 +41,6 @@ friend class ISingleton<LaunchPointList>;
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);

Expand Down
6 changes: 5 additions & 1 deletion src/base/LunaTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
35 changes: 13 additions & 22 deletions src/base/RunningAppList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);

Expand All @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/base/RunningAppList.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ friend class ISingleton<RunningAppList>;
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);
Expand Down
2 changes: 1 addition & 1 deletion src/bus/client/NativeContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/bus/client/WAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion src/bus/service/ApplicationManager.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/bus/service/ApplicationManager.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/conf/RuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
5 changes: 3 additions & 2 deletions src/conf/RuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ friend class ISingleton<RuntimeInfo> ;

bool isInContainer()
{
return m_isInContainer;
return false;
// TODO this should be enabled to support multiple profiles
// return m_isInContainer;
}


private:
RuntimeInfo();

Expand Down

0 comments on commit 8a1443b

Please sign in to comment.