summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2018-11-21 13:42:08 -0500
committerGitHub <noreply@github.com>2018-11-21 13:42:08 -0500
commita751881e1f4e04a6af24552be70d691d8076c933 (patch)
tree59bff1fb166fa60b908aeb458365004dbc905af8
parent8c761e3fcaf4a7f052df405f129fedee7930258a (diff)
parentcfd35969fae824e1472b4ee064ea1c558afc4fb5 (diff)
downloadsdl_core-a751881e1f4e04a6af24552be70d691d8076c933.tar.gz
Merge pull request #2751 from smartdevicelink/feature/cloud_app_policies_initcloudapp
Initialize new Cloud App in Policies
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc37
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc3
-rw-r--r--src/components/include/policy/policy_external/policy/policy_manager.h6
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_manager.h7
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_cache_manager.h1
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_manager.h1
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h1
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h1
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager.h8
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager_interface.h8
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h6
-rw-r--r--src/components/policy/policy_external/src/cache_manager.cc19
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc4
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager.h8
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager_interface.h8
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h7
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc21
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc4
18 files changed, 149 insertions, 1 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc
index d92f458587..0beb7631c7 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloudapp_properties_request.cc
@@ -35,7 +35,42 @@ void SetCloudAppPropertiesRequest::Run() {
return;
}
- policy_handler_.OnSetCloudAppProperties(*message_);
+ smart_objects::SmartObject cloud_app_properties(smart_objects::SmartType_Map);
+
+ cloud_app_properties[strings::msg_params][strings::app_name] =
+ (*message_)[strings::msg_params][strings::app_name];
+ cloud_app_properties[strings::msg_params][strings::app_id] =
+ (*message_)[strings::msg_params][strings::app_id];
+
+ if ((*message_)[strings::msg_params].keyExists(strings::enabled)) {
+ smart_objects::SmartObject enabled =
+ (*message_)[strings::msg_params][strings::enabled];
+ cloud_app_properties[strings::msg_params][strings::enabled] = enabled;
+ }
+ if ((*message_)[strings::msg_params].keyExists(
+ strings::cloud_app_auth_token)) {
+ smart_objects::SmartObject auth_token =
+ (*message_)[strings::msg_params][strings::cloud_app_auth_token];
+ cloud_app_properties[strings::msg_params][strings::cloud_app_auth_token] =
+ auth_token;
+ }
+ if ((*message_)[strings::msg_params].keyExists(
+ strings::cloud_transport_type)) {
+ smart_objects::SmartObject transport_type =
+ (*message_)[strings::msg_params][strings::cloud_transport_type];
+ cloud_app_properties[strings::msg_params][strings::cloud_transport_type] =
+ transport_type;
+ }
+ if ((*message_)[strings::msg_params].keyExists(
+ strings::hybrid_app_preference)) {
+ smart_objects::SmartObject hybrid_app_preference =
+ (*message_)[strings::msg_params][strings::hybrid_app_preference];
+ cloud_app_properties[strings::msg_params][strings::hybrid_app_preference] =
+ hybrid_app_preference;
+ }
+
+ policy_handler_.OnSetCloudAppProperties(cloud_app_properties);
+
SendResponse(true, mobile_apis::Result::SUCCESS);
}
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 8c026c8c75..c603659353 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -1906,6 +1906,9 @@ void PolicyHandler::OnSetCloudAppProperties(
return;
}
std::string policy_app_id(msg_params[strings::app_id].asString());
+
+ policy_manager_->InitCloudApp(policy_app_id);
+
if (msg_params.keyExists(strings::enabled)) {
policy_manager_->SetCloudAppEnabled(policy_app_id,
msg_params[strings::enabled].asBool());
diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h
index 37c8a902f1..92c0305279 100644
--- a/src/components/include/policy/policy_external/policy/policy_manager.h
+++ b/src/components/include/policy/policy_external/policy/policy_manager.h
@@ -556,6 +556,12 @@ class PolicyManager : public usage_statistics::StatisticsManager {
std::string& hybrid_app_preference) const = 0;
/**
+ * @ brief Initialize new cloud app in the policy table
+ * @ param policy_app_id Application ID
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id) = 0;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h
index d22f52bfed..b2d48585f4 100644
--- a/src/components/include/policy/policy_regular/policy/policy_manager.h
+++ b/src/components/include/policy/policy_regular/policy/policy_manager.h
@@ -536,6 +536,13 @@ class PolicyManager : public usage_statistics::StatisticsManager {
std::string& hybrid_app_preference) const = 0;
/**
+ * @ brief Initialize new cloud app in the policy table
+ * @ param policy_app_id Application ID
+ */
+
+ virtual void InitCloudApp(const std::string& policy_app_id) = 0;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
index db3f37fb91..da2b4cc2a1 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
@@ -86,6 +86,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
std::string& auth_token,
std::string& cloud_transport_type,
std::string& hybrid_app_preference));
+ MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id));
MOCK_METHOD2(SetCloudAppEnabled,
void(const std::string& policy_app_id, const bool enabled));
MOCK_METHOD2(SetAppAuthToken,
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
index 1eabb78019..72dcb147e3 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h
@@ -194,6 +194,7 @@ class MockPolicyManager : public PolicyManager {
std::string& auth_token,
std::string& cloud_transport_type,
std::string& hybrid_app_preference));
+ MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id));
MOCK_METHOD2(SetCloudAppEnabled,
void(const std::string& policy_app_id, const bool enabled));
MOCK_METHOD2(SetAppAuthToken,
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
index 3d8dc4116a..24fe9b2393 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
@@ -73,6 +73,7 @@ class MockCacheManagerInterface : public CacheManagerInterface {
std::string& auth_token,
std::string& cloud_transport_type,
std::string& hybrid_app_preference));
+ MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id));
MOCK_METHOD2(SetCloudAppEnabled,
void(const std::string& policy_app_id, const bool enabled));
MOCK_METHOD2(SetAppAuthToken,
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
index a28ea32108..a5ce488e1a 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h
@@ -191,6 +191,7 @@ class MockPolicyManager : public PolicyManager {
std::string& auth_token,
std::string& cloud_transport_type,
std::string& hybrid_app_preference));
+ MOCK_METHOD1(InitCloudApp, void(const std::string& policy_app_id));
MOCK_METHOD2(SetCloudAppEnabled,
void(const std::string& policy_app_id, const bool enabled));
MOCK_METHOD2(SetAppAuthToken,
diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h
index 98f279b345..3344b149e4 100644
--- a/src/components/policy/policy_external/include/policy/cache_manager.h
+++ b/src/components/policy/policy_external/include/policy/cache_manager.h
@@ -191,6 +191,14 @@ class CacheManager : public CacheManagerInterface {
std::string& hybrid_app_preference) const;
/**
+ * Initializes a new cloud application with default policies
+ * Then adds cloud specific policies
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id);
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
index 2a334876ae..6a172e6f4b 100644
--- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h
+++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
@@ -199,6 +199,14 @@ class CacheManagerInterface {
std::string& hybrid_app_preference) const = 0;
/**
+ * Initializes a new cloud application with default policies
+ * Then adds cloud specific policies
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id) = 0;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
index 6d4cbbf773..399c95170d 100644
--- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
@@ -603,6 +603,12 @@ class PolicyManagerImpl : public PolicyManager {
std::string& hybrid_app_preference) const OVERRIDE;
/**
+ * @ brief Initialize new cloud app in the policy table
+ * @ param policy_app_id Application ID
+ */
+ void InitCloudApp(const std::string& policy_app_id) OVERRIDE;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc
index dc0838d429..8cec6ef91c 100644
--- a/src/components/policy/policy_external/src/cache_manager.cc
+++ b/src/components/policy/policy_external/src/cache_manager.cc
@@ -1435,6 +1435,25 @@ void CacheManager::GetCloudAppParameters(
}
}
+void CacheManager::InitCloudApp(const std::string& policy_app_id) {
+ CACHE_MANAGER_CHECK_VOID();
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+
+ policy_table::ApplicationPolicies& policies =
+ pt_->policy_table.app_policies_section.apps;
+ policy_table::ApplicationPolicies::const_iterator default_iter =
+ policies.find(kDefaultId);
+ policy_table::ApplicationPolicies::const_iterator app_iter =
+ policies.find(policy_app_id);
+ if (default_iter != policies.end()) {
+ if (app_iter == policies.end()) {
+ policies[policy_app_id] = policies[kDefaultId];
+ }
+ }
+ // Add cloud app specific policies
+ Backup();
+}
+
void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id,
const bool enabled) {
policy_table::ApplicationPolicies& policies =
diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc
index df474268ba..0844edd8eb 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -747,6 +747,10 @@ void PolicyManagerImpl::GetCloudAppParameters(
hybrid_app_preference);
}
+void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) {
+ cache_->InitCloudApp(policy_app_id);
+}
+
void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id,
const bool enabled) {
cache_->SetCloudAppEnabled(policy_app_id, enabled);
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h
index a4ae45d604..8c8f0c55c6 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager.h
@@ -179,6 +179,14 @@ class CacheManager : public CacheManagerInterface {
std::string& hybrid_app_preference) const;
/**
+ * Initializes a new cloud application with default policies
+ * Then adds cloud specific policies
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id);
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
index f0ee9c2b25..50b546ecc5 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
@@ -185,6 +185,14 @@ class CacheManagerInterface {
std::string& hybrid_app_preference) const = 0;
/**
+ * Initializes a new cloud application with default policies
+ * Then adds cloud specific policies
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id) = 0;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
index 0a0c260a96..20a37717a7 100644
--- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
@@ -597,6 +597,13 @@ class PolicyManagerImpl : public PolicyManager {
std::string& hybrid_app_preference) const OVERRIDE;
/**
+ * @ brief Initialize new cloud app in the policy table
+ * @ param policy_app_id Application ID
+ */
+
+ void InitCloudApp(const std::string& policy_app_id) OVERRIDE;
+
+ /**
* @brief Enable or disable a cloud application in the HMI
* @param enabled Cloud app enabled state
*/
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index c4b3d8db53..ca61a338f1 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -728,6 +728,27 @@ void CacheManager::GetCloudAppParameters(
}
}
+void CacheManager::InitCloudApp(const std::string& policy_app_id) {
+ CACHE_MANAGER_CHECK_VOID();
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+
+ policy_table::ApplicationPolicies& policies =
+ pt_->policy_table.app_policies_section.apps;
+ policy_table::ApplicationPolicies::const_iterator default_iter =
+ policies.find(kDefaultId);
+ policy_table::ApplicationPolicies::const_iterator app_iter =
+ policies.find(policy_app_id);
+
+ if (default_iter != policies.end()) {
+ if (app_iter == policies.end()) {
+ policies[policy_app_id] = policies[kDefaultId];
+ }
+ }
+ // Add cloud app specific policies
+
+ Backup();
+}
+
void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id,
const bool enabled) {
policy_table::ApplicationPolicies& policies =
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index 6e635b7f36..9b2392a015 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -566,6 +566,10 @@ void PolicyManagerImpl::GetCloudAppParameters(
hybrid_app_preference);
}
+void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) {
+ cache_->InitCloudApp(policy_app_id);
+}
+
void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id,
const bool enabled) {
cache_->SetCloudAppEnabled(policy_app_id, enabled);