summaryrefslogtreecommitdiff
path: root/src/components/policy
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-08-26 16:45:19 -0400
committerGitHub <noreply@github.com>2019-08-26 16:45:19 -0400
commitc42cbc9cf60754baac573193f7f8ca8222157c2e (patch)
treea4c3e581b4d9c8c2a6cbdc029323a68b50a0829f /src/components/policy
parent8db0c2601921fdd368bf86133780746b532c40f5 (diff)
parent55c67ea33906799127c45ddfad165571b2d98103 (diff)
downloadsdl_core-c42cbc9cf60754baac573193f7f8ca8222157c2e.tar.gz
Merge pull request #2980 from smartdevicelink/feature/widget_support
Feature/widget support
Diffstat (limited to 'src/components/policy')
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/enums.h10
-rw-r--r--src/components/policy/policy_external/src/policy_table/enums.cc10
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_table/enums.h10
-rw-r--r--src/components/policy/policy_regular/src/policy_table/enums.cc18
-rw-r--r--src/components/policy/policy_regular/test/policy_manager_impl_test.cc163
5 files changed, 211 insertions, 0 deletions
diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h
index 2cff10d8be..d3aee9dcf8 100644
--- a/src/components/policy/policy_external/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h
@@ -492,6 +492,16 @@ enum FunctionID {
ShowAppMenuID = 59,
/**
+ * @brief CreateWindowID.
+ */
+ CreateWindowID = 60,
+
+ /**
+ * @brief DeleteWindowID.
+ */
+ DeleteWindowID = 61,
+
+ /**
* @brief OnHMIStatusID.
*/
OnHMIStatusID = 32768,
diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc
index 5628dd5729..6f60b43af9 100644
--- a/src/components/policy/policy_external/src/policy_table/enums.cc
+++ b/src/components/policy/policy_external/src/policy_table/enums.cc
@@ -1169,6 +1169,16 @@ bool EnumFromJsonString(const std::string& literal, FunctionID* result) {
return true;
}
+ if ("CreateWindow" == literal) {
+ *result = CreateWindowID;
+ return true;
+ }
+
+ if ("DeleteWindow" == literal) {
+ *result = DeleteWindowID;
+ return true;
+ }
+
if ("CloseApplication" == literal) {
*result = CloseApplicationID;
return true;
diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
index 840f429bf7..899e40993e 100644
--- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
@@ -477,6 +477,16 @@ enum FunctionID {
ShowAppMenuID = 59,
/**
+ * @brief CreateWindowID.
+ */
+ CreateWindowID = 60,
+
+ /**
+ * @brief DeleteWindowID.
+ */
+ DeleteWindowID = 61,
+
+ /**
* @brief OnHMIStatusID.
*/
OnHMIStatusID = 32768,
diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc
index d753c22b49..56bbd53762 100644
--- a/src/components/policy/policy_regular/src/policy_table/enums.cc
+++ b/src/components/policy/policy_regular/src/policy_table/enums.cc
@@ -863,6 +863,10 @@ bool IsValidEnum(FunctionID val) {
return true;
case CancelInteractionID:
return true;
+ case CreateWindowID:
+ return true;
+ case DeleteWindowID:
+ return true;
case CloseApplicationID:
return true;
case ShowAppMenuID:
@@ -1034,6 +1038,10 @@ const char* EnumToJsonString(FunctionID val) {
return "UnpublishAppService";
case CancelInteractionID:
return "CancelInteraction";
+ case CreateWindowID:
+ return "CreateWindow";
+ case DeleteWindowID:
+ return "DeleteWindow";
case CloseApplicationID:
return "CloseApplication";
case ShowAppMenuID:
@@ -1372,6 +1380,16 @@ bool EnumFromJsonString(const std::string& literal, FunctionID* result) {
return true;
}
+ if ("CreateWindow" == literal) {
+ *result = CreateWindowID;
+ return true;
+ }
+
+ if ("DeleteWindow" == literal) {
+ *result = DeleteWindowID;
+ return true;
+ }
+
if ("CloseApplication" == literal) {
*result = CloseApplicationID;
return true;
diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
index 3b07506981..eb06856eae 100644
--- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
+++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc
@@ -247,6 +247,53 @@ class PolicyManagerImplTest2 : public ::testing::Test {
ASSERT_TRUE(manager->InitPT(file_name, &policy_settings_));
}
+ Json::Value AddWidgetSupportToPt(const std::string& section_name,
+ const uint32_t group_number) {
+ std::ifstream ifile("sdl_preloaded_pt.json");
+ Json::Reader reader;
+ Json::Value root(Json::objectValue);
+ if (ifile.is_open() && reader.parse(ifile, root, true)) {
+ auto& groups =
+ root["policy_table"]["app_policies"][section_name]["groups"];
+ if (groups.empty()) {
+ groups = Json::Value(Json::arrayValue);
+ }
+ groups[group_number] = Json::Value("WidgetSupport");
+ }
+ ifile.close();
+ return root;
+ }
+
+ std::string AddWidgetSupportToPt(Json::Value* root,
+ const std::string& section_name,
+ const uint32_t group_number) {
+ if (root) {
+ auto& groups =
+ (*root)["policy_table"]["app_policies"][section_name]["groups"];
+ if (groups.empty()) {
+ groups = Json::Value(Json::arrayValue);
+ }
+ groups[group_number] = Json::Value("WidgetSupport");
+ return root->toStyledString();
+ }
+ return std::string();
+ }
+
+ std::string AddWidgetSupportToFunctionalGroups(Json::Value* root,
+ const std::string& rpc_name,
+ const std::string& hmi_level) {
+ if (root) {
+ Json::Value val(Json::objectValue);
+ Json::Value val2(Json::arrayValue);
+ val2[0] = hmi_level;
+ val[rpc_name]["hmi_levels"] = val2;
+ (*root)["policy_table"]["functional_groupings"]["WidgetSupport"]["rpcs"] =
+ val;
+ return root->toStyledString();
+ }
+ return std::string();
+ }
+
void AddRTtoPT(const std::string& update_file_name,
const std::string& section_name,
const uint32_t rt_number,
@@ -588,6 +635,122 @@ TEST_F(PolicyManagerImplTest2,
ASSERT_TRUE(output.list_of_allowed_params.empty());
}
+TEST_F(
+ PolicyManagerImplTest2,
+ CheckPermissions_PersistsWidgetAppPermissionsAfter_PTU_ExpectRPCAllowed) {
+ // Arrange
+ CreateLocalPT("sdl_preloaded_pt.json");
+ (manager->GetCache())->AddDevice(dev_id1, "Bluetooth");
+ (manager->GetCache())
+ ->SetDeviceData(dev_id1,
+ "hardware IPX",
+ "v.8.0.1",
+ "Android",
+ "4.4.2",
+ "Life",
+ 2,
+ "Bluetooth");
+ EXPECT_CALL(listener, OnCurrentDeviceIdUpdateRequired(_, app_id1))
+ .WillRepeatedly(Return(dev_id1));
+ manager->SetUserConsentForDevice(dev_id1, true);
+ // Add app from consented device. App will be assigned with default policies
+ manager->AddApplication(
+ app_id1, app_id1, HmiTypes(policy_table::AHT_DEFAULT));
+ EXPECT_CALL(listener, GetDevicesIds(app_id1))
+ .WillRepeatedly(Return(transport_manager::DeviceList()));
+ // Act
+ const char* const rpc_name = "CreateWindow";
+ const char* const hmi_level = "NONE";
+ const uint32_t group_number = 0;
+ Json::Value root = AddWidgetSupportToPt("default", group_number);
+ std::string json =
+ AddWidgetSupportToFunctionalGroups(&root, rpc_name, hmi_level);
+
+ ::policy::BinaryMessage msg(json.begin(), json.end());
+ ASSERT_TRUE(manager->LoadPT("file_pt_update.json", msg));
+
+ ::policy::RPCParams input_params;
+ ::policy::CheckPermissionResult output;
+
+ manager->CheckPermissions(
+ dev_id1, app_id1, hmi_level, rpc_name, input_params, output);
+
+ // Check RPC is allowed
+ EXPECT_EQ(::policy::kRpcAllowed, output.hmi_level_permitted);
+ ASSERT_TRUE(output.list_of_allowed_params.empty());
+ // Act
+ json = AddWidgetSupportToPt(&root, app_id1, group_number);
+ msg = BinaryMessage(json.begin(), json.end());
+ ASSERT_TRUE(manager->LoadPT("file_pt_update.json", msg));
+
+ output.hmi_level_permitted = ::policy::kRpcDisallowed;
+ manager->CheckPermissions(
+ dev_id1, app_id1, hmi_level, rpc_name, input_params, output);
+ // Check RPC is allowed
+ EXPECT_EQ(::policy::kRpcAllowed, output.hmi_level_permitted);
+ ASSERT_TRUE(output.list_of_allowed_params.empty());
+}
+
+TEST_F(
+ PolicyManagerImplTest2,
+ CheckPermissions_AbsenceOfWidgetPermissionsAfter_PTU_ExpectRPCDisallowed) {
+ // Arrange
+ CreateLocalPT("sdl_preloaded_pt.json");
+ (manager->GetCache())->AddDevice(dev_id1, "Bluetooth");
+ (manager->GetCache())
+ ->SetDeviceData(dev_id1,
+ "hardware IPX",
+ "v.8.0.1",
+ "Android",
+ "4.4.2",
+ "Life",
+ 2,
+ "Bluetooth");
+ EXPECT_CALL(listener, OnCurrentDeviceIdUpdateRequired(_, app_id1))
+ .WillRepeatedly(Return(dev_id1));
+ manager->SetUserConsentForDevice(dev_id1, true);
+ // Add app from consented device. App will be assigned with default policies
+ manager->AddApplication(
+ dev_id1, app_id1, HmiTypes(policy_table::AHT_DEFAULT));
+ EXPECT_CALL(listener, GetDevicesIds(app_id1))
+ .WillRepeatedly(Return(transport_manager::DeviceList()));
+ // Act
+ const char* const rpc_name = "DeleteWindow";
+ const char* const hmi_level = "NONE";
+ const uint32_t group_number = 0;
+ Json::Value root = AddWidgetSupportToPt("default", group_number);
+ std::string json =
+ AddWidgetSupportToFunctionalGroups(&root, rpc_name, hmi_level);
+
+ ::policy::BinaryMessage msg(json.begin(), json.end());
+ ASSERT_TRUE(manager->LoadPT("file_pt_update.json", msg));
+
+ ::policy::RPCParams input_params;
+ ::policy::CheckPermissionResult output;
+
+ manager->CheckPermissions(
+ dev_id1, app_id1, hmi_level, rpc_name, input_params, output);
+
+ // Check RPC is allowed
+ EXPECT_EQ(::policy::kRpcAllowed, output.hmi_level_permitted);
+ ASSERT_TRUE(output.list_of_allowed_params.empty());
+ output.hmi_level_permitted = ::policy::kRpcDisallowed;
+ // Act
+ root["policy_table"]["app_policies"][app_id1]["groups"] =
+ Json::Value(Json::arrayValue);
+ root["policy_table"]["app_policies"][app_id1]["groups"][group_number] =
+ Json::Value("Base-4");
+ json = root.toStyledString();
+ msg = BinaryMessage(json.begin(), json.end());
+ ASSERT_TRUE(manager->LoadPT("file_pt_update.json", msg));
+
+ manager->CheckPermissions(
+ dev_id1, app_id1, hmi_level, rpc_name, input_params, output);
+ // Check RPC is disallowed
+ EXPECT_EQ(::policy::kRpcDisallowed, output.hmi_level_permitted);
+ ASSERT_TRUE(output.list_of_allowed_params.empty());
+}
+
TEST_F(PolicyManagerImplTest2,
CheckPermissions_SetAppIDwithPolicies_ExpectRPCAllowed) {
// Arrange