summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_regular
diff options
context:
space:
mode:
authorAndrii Kalinich (GitHub) <AKalinich@luxoft.com>2019-10-23 07:17:00 -0700
committerShobhit Adlakha <ShobhitAd@users.noreply.github.com>2019-10-23 10:17:00 -0400
commit59157f0e79566a5dfcd860bbb220f76843ff519b (patch)
tree6cbc55633c0ee70bfe6ddc5f1b606aae69b89234 /src/components/policy/policy_regular
parentb67c088ea29cd0d7b29f4809a7964b11af80745e (diff)
downloadsdl_core-59157f0e79566a5dfcd860bbb220f76843ff519b.tar.gz
Fix VD items subscriptions after PTU (#3081)
* Fix revoked VD items subscription after PTU There was found an issue that SDL still kept subscriptions for custom vehicle data items even for case when they were removed during PTU. By that reason, SDL was crashing with DCHECK on attempt to unsubscribe from non existing custom data. There was added missing logic of internal unsubscribe in case some custom vehicle data was removed by policies. * Fix sending of UnsubscribeVehicleData Was added a missing part of logic of subscriptions control - cache manager was updated to keep the vehicle data which was removed by last PTU. Custom vehicle data manager was updated to consider the removed vehicle data and also prepare and send unsubscribe requests to HMI for case when some vehicle data was removed and some application was subscribed on it. * fixup! Fix sending of UnsubscribeVehicleData * fixup! Fix sending of UnsubscribeVehicleData * fixup! Fix sending of UnsubscribeVehicleData * fixup! Fix sending of UnsubscribeVehicleData
Diffstat (limited to 'src/components/policy/policy_regular')
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager.h22
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager_interface.h7
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h3
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc62
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc5
5 files changed, 96 insertions, 3 deletions
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 9b0413d7ce..6bd2c4840b 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager.h
@@ -154,6 +154,9 @@ class CacheManager : public CacheManagerInterface {
virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
const;
+ std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems()
+ const OVERRIDE;
+
const boost::optional<bool> LockScreenDismissalEnabledState() const OVERRIDE;
const boost::optional<std::string> LockScreenDismissalWarningMessage(
@@ -919,6 +922,24 @@ class CacheManager : public CacheManagerInterface {
*/
void CheckSnapshotInitialization();
+ /**
+ * @brief Calculates difference between two provided custom vehicle data items
+ * @param items_before list of vehicle data items before PTU was applied
+ * @param items_after list of vehicle data items after PTU was applied
+ * @return list with calculated difference or empty list if two input lists
+ * are equal
+ */
+ policy_table::VehicleDataItems CalculateCustomVdItemsDiff(
+ const policy_table::VehicleDataItems& items_before,
+ const policy_table::VehicleDataItems& items_after) const;
+
+ /**
+ * @brief Sets the custom vehicle data items
+ * @param removed_items list of vehicle data items to set
+ */
+ void SetRemovedCustomVdItems(
+ const policy_table::VehicleDataItems& removed_items);
+
void PersistData();
/**
@@ -945,6 +966,7 @@ class CacheManager : public CacheManagerInterface {
bool update_required;
typedef std::set<std::string> UnpairedDevices;
UnpairedDevices is_unpaired_;
+ policy_table::VehicleDataItems removed_custom_vd_items_;
mutable sync_primitives::RecursiveLock cache_lock_;
sync_primitives::Lock unpaired_lock_;
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 bd03896bfb..a1b4af0f39 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
@@ -162,6 +162,13 @@ class CacheManagerInterface {
const = 0;
/**
+ * @brief Gets vehicle data items removed after the last PTU
+ * @return List of removed vehicle data items
+ */
+ virtual std::vector<policy_table::VehicleDataItem>
+ GetRemovedVehicleDataItems() const = 0;
+
+ /**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
* cloud application
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 178de4a8f0..fc6ec369dc 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
@@ -663,6 +663,9 @@ class PolicyManagerImpl : public PolicyManager {
const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
const OVERRIDE;
+ std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems()
+ const OVERRIDE;
+
/**
* @brief Gets copy of current policy table data
* @return policy_table as json object
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 166a79b89d..9c73d88e63 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -107,6 +107,7 @@ CacheManager::CacheManager()
, pt_(new policy_table::Table)
, backup_(new SQLPTRepresentation())
, update_required(false)
+ , removed_custom_vd_items_()
, settings_(nullptr) {
LOG4CXX_AUTO_TRACE(logger_);
backuper_ = new BackgroundBackuper(this);
@@ -304,6 +305,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
// Apply update for vehicle data
if (update_pt.policy_table.vehicle_data.is_initialized()) {
+ policy_table::VehicleDataItems custom_items_before_apply;
+ if (pt_->policy_table.vehicle_data->schema_items.is_initialized()) {
+ custom_items_before_apply =
+ CollectCustomVDItems(*pt_->policy_table.vehicle_data->schema_items);
+ }
+
if (!update_pt.policy_table.vehicle_data->schema_items.is_initialized() ||
update_pt.policy_table.vehicle_data->schema_items->empty()) {
pt_->policy_table.vehicle_data->schema_items =
@@ -317,9 +324,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
pt_->policy_table.vehicle_data->schema_items =
rpc::Optional<policy_table::VehicleDataItems>(custom_items);
}
- if (update_pt.policy_table.vehicle_data->schema_version.is_initialized() &&
- update_pt.policy_table.vehicle_data->schema_items.is_initialized()) {
- }
+
+ policy_table::VehicleDataItems custom_items_after_apply =
+ *pt_->policy_table.vehicle_data->schema_items;
+ const auto& items_diff = CalculateCustomVdItemsDiff(
+ custom_items_before_apply, custom_items_after_apply);
+ SetRemovedCustomVdItems(items_diff);
}
ResetCalculatedPermissions();
@@ -727,6 +737,12 @@ CacheManager::GetVehicleDataItems() const {
return std::vector<policy_table::VehicleDataItem>();
}
+std::vector<policy_table::VehicleDataItem>
+CacheManager::GetRemovedVehicleDataItems() const {
+ CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>());
+ return removed_custom_vd_items_;
+}
+
Json::Value CacheManager::GetPolicyTableData() const {
return pt_->policy_table.ToJsonValue();
}
@@ -1226,6 +1242,46 @@ void CacheManager::CheckSnapshotInitialization() {
}
}
+policy_table::VehicleDataItems CacheManager::CalculateCustomVdItemsDiff(
+ const policy_table::VehicleDataItems& items_before,
+ const policy_table::VehicleDataItems& items_after) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (items_before.empty()) {
+ LOG4CXX_DEBUG(logger_, "No custom VD items found in policy");
+ return policy_table::VehicleDataItems();
+ }
+
+ if (items_after.empty()) {
+ LOG4CXX_DEBUG(logger_,
+ "All custom VD items were removed after policy update");
+ return items_before;
+ }
+
+ policy_table::VehicleDataItems removed_items;
+ for (auto& item_to_search : items_before) {
+ auto item_predicate =
+ [&item_to_search](const policy_table::VehicleDataItem& item_to_check) {
+ return item_to_search.name == item_to_check.name;
+ };
+
+ auto it =
+ std::find_if(items_after.begin(), items_after.end(), item_predicate);
+ if (items_after.end() == it) {
+ removed_items.push_back(item_to_search);
+ }
+ }
+
+ LOG4CXX_DEBUG(logger_,
+ "Found " << removed_items.size() << " removed VD items");
+ return removed_items;
+}
+
+void CacheManager::SetRemovedCustomVdItems(
+ const policy_table::VehicleDataItems& removed_items) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ removed_custom_vd_items_ = removed_items;
+}
+
void CacheManager::PersistData() {
LOG4CXX_AUTO_TRACE(logger_);
if (backup_.use_count() != 0) {
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 4c3f0763bc..2fef8de1d8 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -721,6 +721,11 @@ PolicyManagerImpl::GetVehicleDataItems() const {
return cache_->GetVehicleDataItems();
}
+std::vector<policy_table::VehicleDataItem>
+PolicyManagerImpl::GetRemovedVehicleDataItems() const {
+ return cache_->GetRemovedVehicleDataItems();
+}
+
Json::Value PolicyManagerImpl::GetPolicyTableData() const {
return cache_->GetPolicyTableData();
}