summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <akutsan@luxoft.com>2019-04-18 16:39:38 +0300
committerigapchuck <igapchuck@luxoft.com>2019-07-24 10:26:36 +0300
commit82b2a6145dce6774182495e1c4b42119dfb6d4d3 (patch)
treefd1972cb65c2001bc431811b31f8fb5132fbc428
parent056173456d80ce93ad8266c928f442d5d20a0f3a (diff)
downloadsdl_core-82b2a6145dce6774182495e1c4b42119dfb6d4d3.tar.gz
Send OnDriverDistraction notification in case if LockScreenDismissal state was changes after policy update.
-rw-r--r--src/components/application_manager/include/application_manager/policies/policy_handler.h4
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc66
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc9
-rw-r--r--src/components/include/policy/policy_regular/policy/policy_listener.h5
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_policy_listener.h1
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h1
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h11
-rw-r--r--src/components/policy/policy_external/src/policy_manager_impl.cc13
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc3
9 files changed, 83 insertions, 30 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h
index 68ab57ff64..cda3b5c1ed 100644
--- a/src/components/application_manager/include/application_manager/policies/policy_handler.h
+++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h
@@ -662,6 +662,8 @@ class PolicyHandler : public PolicyHandlerInterface,
void OnDeviceSwitching(const std::string& device_id_from,
const std::string& device_id_to) FINAL;
+ void OnLockScreenDismissalStateChanged() FINAL;
+
protected:
/**
* Starts next retry exchange policy table
@@ -808,7 +810,6 @@ class PolicyHandler : public PolicyHandlerInterface,
std::vector<FunctionalGroupPermission> CollectAppPermissions(
const uint32_t connection_key);
- private:
static const std::string kLibrary;
/**
@@ -818,7 +819,6 @@ class PolicyHandler : public PolicyHandlerInterface,
*/
void GetRegisteredLinks(std::map<std::string, std::string>& out_links) const;
- private:
mutable sync_primitives::RWLock policy_manager_lock_;
std::shared_ptr<PolicyManager> policy_manager_;
void* dl_handle_;
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index ae10478e5e..94278790e7 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -3907,42 +3907,54 @@ void ApplicationManagerImpl::SendDriverDistractionState(
LOG4CXX_WARN(logger_, "DriverDistractionState is INVALID_ENUM");
return;
}
- smart_objects::SmartObjectSPtr on_driver_distraction =
- std::make_shared<smart_objects::SmartObject>();
-
- (*on_driver_distraction)[strings::params][strings::message_type] =
- static_cast<int32_t>(application_manager::MessageType::kNotification);
- (*on_driver_distraction)[strings::params][strings::function_id] =
- mobile_api::FunctionID::OnDriverDistractionID;
- (*on_driver_distraction)[strings::msg_params][mobile_notification::state] =
- driver_distraction_state();
- const auto lock_screen_dismissal =
- policy_handler_->LockScreenDismissalEnabledState();
- if (lock_screen_dismissal &&
- hmi_apis::Common_DriverDistractionState::DD_ON ==
- driver_distraction_state()) {
- (*on_driver_distraction)
- [strings::msg_params]
- [mobile_notification::lock_screen_dismissal_enabled] =
- *lock_screen_dismissal;
- }
+ auto create_notification = [application, this]() {
+ auto notification = std::make_shared<smart_objects::SmartObject>();
+ auto& msg_params = (*notification)[strings::msg_params];
+ auto& params = (*notification)[strings::params];
+
+ params[strings::message_type] =
+ static_cast<int32_t>(application_manager::MessageType::kNotification);
+ params[strings::function_id] =
+ static_cast<int32_t>(mobile_apis::FunctionID::OnDriverDistractionID);
+ msg_params[mobile_notification::state] = driver_distraction_state();
+ const auto lock_screen_dismissal =
+ policy_handler_->LockScreenDismissalEnabledState();
+
+ if (lock_screen_dismissal &&
+ hmi_apis::Common_DriverDistractionState::DD_ON ==
+ driver_distraction_state()) {
+ msg_params[mobile_notification::lock_screen_dismissal_enabled] =
+ *lock_screen_dismissal;
+ }
- (*on_driver_distraction)[strings::params][strings::connection_key] =
- application->app_id();
+ params[strings::connection_key] = application->app_id();
+ return notification;
+ };
- const std::string function_id = MessageHelper::StringifiedFunctionID(
- static_cast<mobile_apis::FunctionID::eType>(
- (*on_driver_distraction)[strings::params][strings::function_id]
- .asUInt()));
const RPCParams params;
+ const std::string function_id = MessageHelper::StringifiedFunctionID(
+ mobile_api::FunctionID::OnDriverDistractionID);
const mobile_apis::Result::eType check_result =
CheckPolicyPermissions(application, function_id, params);
if (mobile_api::Result::SUCCESS == check_result) {
- rpc_service_->ManageMobileCommand(on_driver_distraction,
+ rpc_service_->ManageMobileCommand(create_notification(),
commands::Command::SOURCE_SDL);
} else {
- application->PushMobileMessage(on_driver_distraction);
+ MobileMessageQueue messages;
+ application->SwapMobileMessageQueue(messages);
+ messages.erase(
+ std::remove_if(
+ messages.begin(),
+ messages.end(),
+ [](smart_objects::SmartObjectSPtr message) {
+ return (*message)[strings::params][strings::function_id]
+ .asUInt() ==
+ mobile_apis::FunctionID::OnDriverDistractionID;
+ }),
+ messages.end());
+ application->SwapMobileMessageQueue(messages);
+ application->PushMobileMessage(create_notification());
}
}
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 72424b74f9..033df7071f 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -826,6 +826,15 @@ void PolicyHandler::OnDeviceSwitching(const std::string& device_id_from,
policy_manager_->OnDeviceSwitching(device_id_from, device_id_to);
}
+void PolicyHandler::OnLockScreenDismissalStateChanged() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ const auto accessor = application_manager_.applications();
+ const auto apps = accessor.GetData();
+ for (auto& app : apps) {
+ application_manager_.SendDriverDistractionState(app);
+ }
+}
+
void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h
index 0907e42142..d017f97f63 100644
--- a/src/components/include/policy/policy_regular/policy/policy_listener.h
+++ b/src/components/include/policy/policy_regular/policy/policy_listener.h
@@ -157,6 +157,11 @@ class PolicyListener {
virtual void OnUpdateHMIStatus(const std::string& device_id,
const std::string& policy_app_id,
const std::string& hmi_level) = 0;
+
+ /**
+ * @brief Notify Connected mobile apps about changing state LockScreenDismissal
+ */
+ virtual void OnLockScreenDismissalStateChanged() = 0;
};
} // namespace policy
#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_REGULAR_POLICY_POLICY_LISTENER_H_
diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
index 1e42423a03..e6ee086b31 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h
@@ -103,6 +103,7 @@ class MockPolicyListener : public ::policy::PolicyListener {
void(const std::string& device_id,
const std::string& policy_app_id,
const std::string& hmi_level));
+ MOCK_METHOD0(OnLockScreenDismissalStateChanged, void());
};
} // namespace policy_test
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h
index f409100a49..7958bd3304 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h
@@ -96,6 +96,7 @@ class MockPolicyListener : public ::policy::PolicyListener {
void(const std::string& device_id,
const std::string& policy_app_id,
const std::string& hmi_level));
+ MOCK_METHOD0(OnLockScreenDismissalStateChanged, void());
};
} // namespace policy_test
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 1ea85ff6d5..6888e38740 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
@@ -853,6 +853,17 @@ class PolicyManagerImpl : public PolicyManager {
const std::shared_ptr<policy_table::Table> snapshot);
/**
+ * @brief Compares current policies to the updated one.
+ * Trigger actions in case if certain fields after udate was changes.
+ * This function should be called after PT update.
+ * Actions require already updated policy table
+ * @param update Shared pointer to policy table udpate
+ * @param snapshot Shared pointer to old copy of policy table
+ */
+ void CheckPermissionsChangesAfterUpdate(const policy_table::Table& update,
+ const policy_table::Table& snapshot);
+
+ /**
* @brief Processes results from policy table update analysis done by
* CheckPermissionsChanges() by filling ApplicationsPoliciesActions struct
* with actions which should be done for every application and passes them to
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 f56758f0f8..4cefa11dd8 100644
--- a/src/components/policy/policy_external/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_external/src/policy_manager_impl.cc
@@ -491,6 +491,8 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
ProcessAppPolicyCheckResults(
results, pt_update->policy_table.app_policies_section.apps);
+ CheckPermissionsChangesAfterUpdate(*pt_update, *policy_table_snapshot);
+
listener_->OnCertificateUpdated(
*(pt_update->policy_table.module_config.certificate));
@@ -538,6 +540,17 @@ CheckAppPolicyResults PolicyManagerImpl::CheckPermissionsChanges(
return out_results;
}
+void PolicyManagerImpl::CheckPermissionsChangesAfterUpdate(
+ const policy_table::Table& update, const policy_table::Table& snapshot) {
+ const auto new_lock_screen_dismissal_enabled =
+ update.policy_table.module_config.lock_screen_dismissal_enabled;
+ const auto old_lock_screen_dismissal_enabled =
+ snapshot.policy_table.module_config.lock_screen_dismissal_enabled;
+ if (new_lock_screen_dismissal_enabled != old_lock_screen_dismissal_enabled) {
+ listener()->OnLockScreenDismissalStateChanged();
+ }
+}
+
void PolicyManagerImpl::ProcessAppPolicyCheckResults(
const CheckAppPolicyResults& results,
const policy_table::ApplicationPolicies& app_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 ae32908100..c6db002980 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -356,6 +356,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
ForcePTExchange();
return false;
}
+ CheckPermissionsChangesAfterUpdate(*pt_update, *policy_table_snapshot);
listener_->OnCertificateUpdated(
*(pt_update->policy_table.module_config.certificate));
@@ -390,7 +391,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
void PolicyManagerImpl::CheckPermissionsChanges(
const std::shared_ptr<policy_table::Table> pt_update,
const std::shared_ptr<policy_table::Table> snapshot) {
- LOG4CXX_INFO(logger_, "Checking incoming permissions.");
+ LOG4CXX_AUTO_TRACE(logger_);
// Replace predefined policies with its actual setting, e.g. "123":"default"
// to actual values of default section