packageid has been deleted.
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port)
PKG_CHECK_MODULES(TIZEN_DATABASE_DEPS REQUIRED tizen-database)
+PKG_CHECK_MODULES(RAPID_JSON_DEPS REQUIRED RapidJSON)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tool)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(rpc-port)
BuildRequires: pkgconfig(tizen-database)
+BuildRequires: pkgconfig(RapidJSON)
%if 0%{?gcov:1}
BuildRequires: lcov
PKGMGR_INFO_DEPS
TIZEN_DATABASE_DEPS
RPC_PORT_DEPS
+ RAPID_JSON_DEPS
)
TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION} PUBLIC ${TARGET_TIZEN_ACTION_COMMON} "-ldl")
#include "action/action_request_handler.hh"
#include "action/service.hh"
#include "action/sqlite_db.hh"
+#include "action/utils/action_model_converter.hh"
+#include "action/utils/action_validator.hh"
#include "action_request_handler.hh"
#include "common/utils/logging.hh"
-#include "utils/action_model_converter.hh"
-#include "utils/action_model_validator.hh"
namespace {
return "";
}
+void FillActionModelInfo(common::ActionModel& model,
+ const common::ActionSchema& schema) {
+ model.SetType(schema.GetType());
+ switch (schema.GetType()) {
+ case common::ActionType::AppControl:
+ model.SetExtraInfo(schema.GetAppId());
+ break;
+ case common::ActionType::Plugin:
+ model.SetExtraInfo("plugin-path"); // TODO: Set plugin path
+ break;
+ default:
+ break;
+ }
+}
+
} // namespace
namespace action {
common::ActionSchema schema(item);
rpc::ActionSchema action;
action.Setaction_id(schema.GetActionId());
- action.Setpackage_id(schema.GetPackageId());
action.Setcategory(schema.GetCategory());
action.Setdescription(schema.GetDescription());
- action.Settype("app_control"); // TODO
+ action.Settype(ActionModelConverter().ActionTypeToString(schema.GetType()));
// action.Setparameters();
// action.Setprivileges();
actions.push_back(action);
rpc::ActionSchema action;
action.Setaction_id(schema.GetActionId());
- action.Setpackage_id(schema.GetPackageId());
action.Setcategory(schema.GetCategory());
action.Setdescription(schema.GetDescription());
- action.Settype("app_control"); // TODO
+ action.Settype(ActionModelConverter().ActionTypeToString(schema.GetType()));
std::vector<rpc::Parameter> actionparams;
auto params = schema.GetParameters();
for (auto const& iter : params) {
- auto param = rpc::Parameter(iter.GetName(), GetStringFromParameterType(iter.GetType()),
- "", iter.GetDescription(), iter.GetIsRequired());
+ auto param = rpc::Parameter(iter.GetName(),
+ GetStringFromParameterType(iter.GetType()),
+ iter.GetDescription(), iter.GetIsRequired());
actionparams.push_back(param);
}
uid_t uid, rpc::ActionModel& action) {
auto db = std::make_unique<action::SqliteDb>();
std::string schema_json = db->GetAction(action.Getaction_id());
- common::ActionSchema schema(schema_json);
- LOG(DEBUG) << "OnExecute action : " << schema.GetActionId() << " appid: " << schema.GetPackageId();
+ std::string error;
- common::ActionModel model(action.Getjson());
- if (!ActionModelValidator().CheckValid(schema, model)) {
- LOG(ERROR) << "Invalid model : " << action.Getjson();
+ if (!ActionValidator().CheckModelValid(schema_json, action.Getjson(),
+ error)) {
+ LOG(ERROR) << "Invalid model. error: " << error;
return;
}
+ common::ActionSchema schema(schema_json);
+ LOG(DEBUG) << "OnExecute action : " << schema.GetActionId();
+
+ common::ActionModel model(action.Getjson());
+ model.SetType(schema.GetType());
+ FillActionModelInfo(model, schema);
+
auto required_privileges = db->GetRequiredPrivileges(model.GetId());
if (!CheckPrivileges(pid, uid, required_privileges)) {
LOG(ERROR) << "Not allowed to execute action due to missing privileges";
return;
}
- model.SetType(schema.GetType());
auto executor = ActionExecutorFactory::CreateExecutor(instance, model);
executor->SetResultHandler(this);
executor->Execute(model);
}
void ActionRequestHandler::RegisterRequestReplyHandler(
- const std::string& requester, IRequestReplyHandler* handler) {
+ const std::string& requester,
+ IRequestReplyHandler* handler) {
reply_handlers_.emplace(requester, handler);
}
void ActionRequestHandler::UnregisterRequestReplyHandler(
const std::string& requester) {
auto it = std::find_if(reply_handlers_.begin(), reply_handlers_.end(),
- [requester](const auto& iterator) {
- return iterator.first == requester;
- });
+ [requester](const auto& iterator) {
+ return iterator.first == requester;
+ });
if (it != reply_handlers_.end())
reply_handlers_.erase(it);
else
const std::string& result) {
LOG(DEBUG) << "OnResult : " << result << ", from : " << requester;
auto it = std::find_if(reply_handlers_.begin(), reply_handlers_.end(),
- [requester](const auto& iterator) {
- return iterator.first == requester;
- });
- if (it!= reply_handlers_.end())
+ [requester](const auto& iterator) {
+ return iterator.first == requester;
+ });
+ if (it != reply_handlers_.end())
it->second->SendRequestReply(result);
else
LOG(WARNING) << "No handler found for requester :" << requester;
}
// TODO: Convert to app_control handle from action model
- app_control_set_app_id(handle, action_model.GetPackageId().c_str());
+ app_control_set_app_id(handle, action_model.GetAppId().c_str());
auto params = action_model.GetParameters();
- for (auto const& [key, value] : params) {
+ for (auto const& [key, value] : params)
LOG(DEBUG) << "param name : " << key << ", val : " << value;
- app_control_add_extra_data(handle, key.c_str(), value.c_str());
- }
return handle;
}
const common::ActionModel& model) {
plugin_proxy::ActionModel action;
action.Setaction_id(model.GetId());
- action.Setpackage_id(model.GetPackageId());
action.Setjson(model.GetJson());
// action.Setresults();
+++ /dev/null
-/*
- * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "action_model_validator.hh"
-
-namespace action {
-
-bool ActionModelValidator::CheckValid(
- const common::ActionSchema& schema,
- const common::ActionModel& model) const {
- // TODO: Implement this.
- return false;
-}
-
-} // namespace action
+++ /dev/null
-/*
- * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ACTION_ACTION_MODEL_VALIDATOR_HH_
-#define ACTION_ACTION_MODEL_VALIDATOR_HH_
-
-#include "common/action_model.h"
-#include "common/action_schema.h"
-
-namespace action {
-
-class ActionModelValidator {
- public:
- ActionModelValidator() = default;
-
- bool CheckValid(const common::ActionSchema& schema,
- const common::ActionModel& model) const;
-};
-
-} // namespace action
-
-#endif // ACTION_ACTION_MODEL_VALIDATOR_HH_
--- /dev/null
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "action_validator.hh"
+
+#include <rapidjson/document.h>
+#include <rapidjson/error/en.h>
+#include <rapidjson/schema.h>
+
+namespace action {
+bool ActionValidator::CheckSchemaValid(const std::string& schemajson) const {
+ // TODO: implement this.
+ return false;
+}
+
+bool ActionValidator::CheckModelValid(const std::string& schemajson,
+ const std::string& modeljson,
+ std::string& errMsg) const {
+ // TODO: implement this.
+ return true;
+}
+
+} // namespace action
--- /dev/null
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTION_ACTION_VALIDATOR_HH_
+#define ACTION_ACTION_VALIDATOR_HH_
+
+#include <string>
+
+namespace action {
+
+class ActionValidator {
+ public:
+ ActionValidator() = default;
+ bool CheckSchemaValid(const std::string& schemajson) const;
+ bool CheckModelValid(const std::string& schemajson,
+ const std::string& modeljson, std::string& errMsg) const;
+};
+
+} // namespace action
+
+#endif // ACTION_ACTION_VALIDATOR_HH_
: json_str_(std::move(json_str)) {
Json::Value root = ParseJsonFromString(json_str_);
action_id_ = root["name"].asString();
- package_id_ = root["packageId"].asString();
for (auto const& it : root["params"].getMemberNames()) {
std::string key = it;
std::string value = root["params"][key].asString();
return action_id_;
}
-const std::string& ActionModel::GetPackageId() const {
- return package_id_;
+std::string ActionModel::GetAppId() const {
+ if (type_ != ActionType::AppControl)
+ return "";
+
+ return extra_info_;
+}
+
+std::string ActionModel::GetPluginPath() const {
+ if (type_ != ActionType::Plugin)
+ return "";
+
+ return extra_info_;
}
const ActionType ActionModel::GetType() const {
return json_str_;
}
+const std::string& ActionModel::GetExtraInfo() const {
+ return extra_info_;
+}
+
+void ActionModel::SetExtraInfo(std::string info) {
+ extra_info_ = std::move(info);
+}
+
} // namespace common
ActionModel() = default;
explicit ActionModel(std::string json_str);
const std::string& GetId() const;
- const std::string& GetPackageId() const;
+ std::string GetAppId() const;
+ std::string GetPluginPath() const;
const ActionType GetType() const;
void SetType(ActionType type);
const std::vector<std::pair<std::string, std::string>>& GetParameters() const;
const std::string& GetJson() const;
+ const std::string& GetExtraInfo() const;
+ void SetExtraInfo(std::string info);
+
private:
std::string action_id_;
- std::string package_id_;
+ std::string extra_info_; // app_control: appid, plugin: plugin path
std::string json_str_;
ActionType type_ = ActionType::InvalidType;
std::vector<std::pair<std::string, std::string>> parameters_;
Json::Value root = ParseJsonFromString(json_str);
action_id_ = root["name"].asString();
- package_id_ = root["appId"].asString(); // TODO: Change to packageId.
+ appid_ = root["appId"].asString(); // TODO: Change to details::appId
category_ = root["category"].asString();
description_ = root["desc"].asString();
type_ = GetActionTypeFromString(root["type"].asString());
}
}
-ActionSchema::ActionSchema(std::string action_id, std::string package_id,
+ActionSchema::ActionSchema(std::string action_id, std::string appid,
std::string category, std::string description,
std::vector<ActionParameter> parameters,
std::vector<std::string> privileges)
- : action_id_(std::move(action_id)), package_id_(std::move(package_id)),
+ : action_id_(std::move(action_id)), appid_(std::move(appid)),
category_(std::move(category)), description_(std::move(description)),
parameters_(std::move(parameters)), privileges_(std::move(privileges)) {
}
action_id_ = std::move(action_id);
}
-const std::string& ActionSchema::GetPackageId() const {
- return package_id_;
+const std::string& ActionSchema::GetAppId() const {
+ return appid_;
}
-void ActionSchema::SetPackageId(std::string package_id) {
- package_id_ = std::move(package_id);
+void ActionSchema::SetAppId(std::string appid) {
+ appid_ = std::move(appid);
}
const std::string& ActionSchema::GetCategory() const {
public:
ActionSchema();
explicit ActionSchema(const std::string& json_str);
- explicit ActionSchema(std::string action_id, std::string package_id,
+ explicit ActionSchema(std::string action_id, std::string appid,
std::string category, std::string description,
std::vector<ActionParameter> parameters,
std::vector<std::string> privileges);
const std::string& GetActionId() const;
void SetActionId(std::string action_id);
- const std::string& GetPackageId() const;
- void SetPackageId(std::string package_id);
+ const std::string& GetAppId() const;
+ void SetAppId(std::string app_id);
const std::string& GetCategory() const;
void SetCategory(std::string category);
private:
std::string action_id_;
- std::string package_id_;
+ std::string appid_;
std::string category_;
ActionType type_ = ActionType::InvalidType;
std::string description_;
private:
void PrintAction(const rpc_port::plugin_manager_stub::ActionModel& action) {
- LOG(INFO) << "Action id: " << action.Getaction_id();
- LOG(INFO) << "Package id: " << action.Getpackage_id();
+ LOG(INFO) << "Action name: " << action.Getaction_id();
LOG(INFO) << "Json: " << action.Getjson();
}
};
TEST(ActionModelConverterTest, ConvertToAction) {
std::string json = R"({
"name": "test_action",
- "packageId": "com.example.test",
"params": {
"param": "value",
}
ActionModelConverter().ConvertToAction(common_model);
EXPECT_EQ(action.Getaction_id(), "test_action");
- EXPECT_EQ(action.Getpackage_id(), "com.example.test");
EXPECT_EQ(action.Getjson(), json);
}
TEST(ActionModelTest, JsonInitialization) {
ActionModel model(R"({
"name": "new_action",
- "packageId": "new_package",
"params": {
"param1": "hello1",
"param2": "hello2",
model.SetType(ActionType::AppControl);
EXPECT_EQ("new_action", model.GetId());
- EXPECT_EQ("new_package", model.GetPackageId());
EXPECT_EQ(2, model.GetParameters().size());
const auto& parameters = model.GetParameters();
EXPECT_EQ(2, parameters.size());
TEST(ActionModelTest, EmptyInitialization) {
ActionModel model;
EXPECT_EQ("", model.GetId());
- EXPECT_EQ("", model.GetPackageId());
+ EXPECT_EQ("", model.GetAppId());
EXPECT_EQ(0, model.GetParameters().size());
EXPECT_EQ(ActionType::InvalidType, model.GetType());
}
TEST_F(ActionSchemaTest, ValidJsonParsing) {
ActionSchema schema(valid_json_);
EXPECT_EQ(schema.GetActionId(), "test_action");
- EXPECT_EQ(schema.GetPackageId(), "com.example.app");
+ EXPECT_EQ(schema.GetAppId(), "com.example.app");
EXPECT_EQ(schema.GetCategory(), "test_category");
EXPECT_EQ(schema.GetDescription(), "Test action description");
EXPECT_EQ(schema.GetType(), ActionType::AppControl);
TEST_F(ActionSchemaTest, InvalidJsonParsing) {
ActionSchema invalid_schema(invalid_json_);
EXPECT_EQ(invalid_schema.GetActionId().empty(), true);
- EXPECT_EQ(invalid_schema.GetPackageId().empty(), true);
+ EXPECT_EQ(invalid_schema.GetAppId().empty(), true);
EXPECT_EQ(invalid_schema.GetCategory().empty(), true);
EXPECT_EQ(invalid_schema.GetDescription().empty(), true);
EXPECT_EQ(invalid_schema.GetType(), ActionType::InvalidType);
TEST_F(ActionSchemaTest, SettersAndGetters) {
ActionSchema schema;
schema.SetActionId("new_id");
- schema.SetPackageId("new_package");
+ schema.SetAppId("new_package");
schema.SetCategory("new_category");
schema.SetDescription("new_desc");
schema.SetType(ActionType::Plugin);
EXPECT_EQ(schema.GetActionId(), "new_id");
- EXPECT_EQ(schema.GetPackageId(), "new_package");
+ EXPECT_EQ(schema.GetAppId(), "new_package");
EXPECT_EQ(schema.GetCategory(), "new_category");
EXPECT_EQ(schema.GetDescription(), "new_desc");
EXPECT_EQ(schema.GetType(), ActionType::Plugin);
TEST_F(ActionSchemaTest, DefaultConstructor) {
ActionSchema default_schema;
EXPECT_TRUE(default_schema.GetActionId().empty());
- EXPECT_TRUE(default_schema.GetPackageId().empty());
+ EXPECT_TRUE(default_schema.GetAppId().empty());
EXPECT_TRUE(default_schema.GetCategory().empty());
EXPECT_TRUE(default_schema.GetDescription().empty());
EXPECT_EQ(default_schema.GetType(), ActionType::InvalidType);
struct Parameter {
string key;
string type;
- string value;
string description;
bool is_requied;
}
struct ActionSchema {
string action_id;
- string package_id;
string category;
string description;
string type;
struct ActionModel {
string action_id;
- string package_id;
string json;
}
IEventListener {
public:
Execute()
- : ActionTool("execute", "Execute", "execute <action id> <package_id> <json string>"),
+ : ActionTool("execute", "Execute", "execute <action id> <json string>"),
proxy_(this, kStubAppId) {}
virtual ~Execute() {}
}
int Run(int argc, char** argv) override {
- if (argc < 4) {
+ if (argc < 3) {
Usage();
return -1;
}
std::vector<rpc_port::tizen_action_service_proxy::Parameter> actionparams;
std::string action_id = std::string(argv[2]);
- std::string package_id = std::string(argv[3]);
- std::string json = std::string(argv[4]);
+ std::string json = std::string(argv[3]);
action.Setaction_id(action_id);
- action.Setpackage_id(package_id);
- _E("id : %s, package_id : %s", action_id.c_str(), package_id.c_str());
+ _E("action name: %s", action_id.c_str());
action.Setjson(json);
try {
int ret = proxy_.Execute(action);
try {
auto action = proxy_.GetAction(std::move(action_id));
_D("id: %s --------------------", action.Getaction_id().c_str());
- _D("package: %s", action.Getpackage_id().c_str());
_D("category: %s", action.Getcategory().c_str());
_D("description: %s", action.Getdescription().c_str());
_D("Actions cnt(%zu)", actions.size());
for (auto action : actions) {
_D("id: %s --------------------", action.Getaction_id().c_str());
- _D("package_id: %s", action.Getpackage_id().c_str());
+ _D("type: %s", action.Gettype().c_str());
_D("category: %s", action.Getcategory().c_str());
_D("description: %s", action.Getdescription().c_str());