Skip to content

Commit

Permalink
Fix OnPermissionChangeNotif data corruption
Browse files Browse the repository at this point in the history
Fixes : smartdevicelink#2961

fix sending OnPermissionChanged after PTU with removing functional
group. OnPermissionChange notification is now sent after applying PTU

Replace ModuleConfig with Whole PT
  • Loading branch information
mkorniichuk authored and LuxoftAKutsan committed Aug 29, 2019
1 parent 9859f35 commit 47cfef3
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class PolicyHandler : public PolicyHandlerInterface,
virtual DeviceConsent GetUserConsentForDevice(
const std::string& device_id) const OVERRIDE;

policy_table::ModuleConfig GetModuleConfigData() const OVERRIDE;
Json::Value GetPolicyTableData() const OVERRIDE;

/**
* @brief Sets HMI default type for specified application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,8 @@ DeviceConsent PolicyHandler::GetUserConsentForDevice(
return policy_manager_->GetUserConsentForDevice(device_id);
}

policy_table::ModuleConfig PolicyHandler::GetModuleConfigData() const {
return policy_manager_->GetModuleConfigData();
Json::Value PolicyHandler::GetPolicyTableData() const {
return policy_manager_->GetPolicyTableData();
}

bool PolicyHandler::GetDefaultHmi(const std::string& device_id,
Expand Down
2 changes: 0 additions & 2 deletions src/components/application_manager/src/rpc_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ void RPCServiceImpl::SendMessageToMobile(
void RPCServiceImpl::SendMessageToHMI(
const commands::MessageSharedPtr message) {
LOG4CXX_AUTO_TRACE(logger_);

if (!message) {
LOG4CXX_WARN(logger_, "Null-pointer message received.");
NOTREACHED();
Expand Down Expand Up @@ -568,7 +567,6 @@ void RPCServiceImpl::SendMessageToHMI(
"Cannot send message to HMI: failed to create string");
return;
}

messages_to_hmi_.PostMessage(impl::MessageToHmi(message_to_send));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PolicyHandlerInterface : public VehicleDataItemProvider {
EndpointUrls& out_end_points) = 0;
virtual void GetUpdateUrls(const uint32_t service_type,
EndpointUrls& out_end_points) = 0;
virtual policy_table::ModuleConfig GetModuleConfigData() const = 0;
virtual Json::Value GetPolicyTableData() const = 0;
virtual std::string GetLockScreenIconUrl() const = 0;
virtual std::string GetIconUrl(const std::string& policy_app_id) const = 0;
virtual uint32_t NextRetryTimeout() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ class PolicyManager : public usage_statistics::StatisticsManager {
virtual const std::vector<std::string> GetAppRequestSubTypes(
const std::string& policy_app_id) const = 0;

/**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
virtual Json::Value GetPolicyTableData() const = 0;

/**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@ class PolicyManager : public usage_statistics::StatisticsManager {
const = 0;

/**
* @brief Gets module config data from policy table
* @return ModuleConfig section of pilicy_table
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
virtual policy_table::ModuleConfig GetModuleConfigData() const = 0;
virtual Json::Value GetPolicyTableData() const = 0;
/**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
void(const std::string& device_id,
const std::string& policy_app_id,
const policy::Permissions& permissions));
MOCK_CONST_METHOD0(GetModuleConfigData, policy_table::ModuleConfig());
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
MOCK_CONST_METHOD0(
GetVehicleDataItems,
const std::vector<rpc::policy_table_interface_base::VehicleDataItem>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
MOCK_METHOD0(TimeoutResponse, int());
MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds));
MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id));
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
void(std::vector<std::string>& enabled_apps));
MOCK_CONST_METHOD7(GetCloudAppParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class MockPolicyManager : public PolicyManager {
const std::vector<std::string>(
const transport_manager::DeviceHandle& device_handle,
const std::string policy_app_id));
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
void(std::vector<std::string>& enabled_apps));
MOCK_CONST_METHOD7(GetCloudAppParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MockCacheManagerInterface : public CacheManagerInterface {
MOCK_METHOD0(ResetIgnitionCycles, void());
MOCK_METHOD0(TimeoutResponse, int());
MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds));
MOCK_CONST_METHOD0(GetModuleConfigData, policy_table::ModuleConfig());
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
MOCK_CONST_METHOD0(GetVehicleDataItems,
const std::vector<policy_table::VehicleDataItem>());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class MockPolicyManager : public PolicyManager {
MOCK_CONST_METHOD1(
GetAppRequestTypes,
const std::vector<std::string>(const std::string policy_app_id));
MOCK_CONST_METHOD0(GetModuleConfigData, policy_table::ModuleConfig());
MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value());
MOCK_CONST_METHOD0(GetVehicleDataItems,
const std::vector<policy_table::VehicleDataItem>());
MOCK_CONST_METHOD1(GetEnabledCloudApps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ class CacheManager : public CacheManagerInterface {
const boost::optional<std::string> LockScreenDismissalWarningMessage(
const std::string& language) const OVERRIDE;

/**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
virtual Json::Value GetPolicyTableData() const OVERRIDE;

/**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
Expand Down Expand Up @@ -848,6 +854,22 @@ class CacheManager : public CacheManagerInterface {
void OnDeviceSwitching(const std::string& device_id_from,
const std::string& device_id_to) OVERRIDE;

/**
* @brief Method for separate standard vehicle data items from custom
* @param full vehicle data items during PTU
* @return array with only standart vehicle items
*/
static policy_table::VehicleDataItems CollectRPCSpecVDItems(
const policy_table::VehicleDataItems& vd_items);

/**
* @brief Method for separate standard vehicle data items from custom
* @param full vehicle data items during PTU
* @return array with only custom vehicle items
*/
static policy_table::VehicleDataItems CollectCustomVDItems(
const policy_table::VehicleDataItems& vd_items);

private:
std::string currentDateTime();
struct AppHMITypeToString {
Expand Down Expand Up @@ -1022,6 +1044,24 @@ class CacheManager : public CacheManagerInterface {
void MergeCFM(const policy_table::PolicyTable& new_pt,
policy_table::PolicyTable& pt);

/**
* @brief MergeVD allows to merge VehicleDataItems section by
*definite rules.
*
* The rules are:
* 1. If vehicle_data_items key is not presented in the updated PolicyTable,
* update for VehicleDataItems should be ignored.
* 2. If vehicle_data_items presented in updated PolicyTable, the
* VehicleDataItems in the database (LocalPT) should be overwritten with
* updated data.
*
* @param new_pt the policy table loaded from updated preload JSON file.
*
* @param pt the exists database
*/
void MergeVD(const policy_table::PolicyTable& new_pt,
policy_table::PolicyTable& pt);

void InitBackupThread();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class CacheManagerInterface {
*/
virtual bool SecondsBetweenRetries(std::vector<int>& seconds) = 0;

/**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
virtual Json::Value GetPolicyTableData() const = 0;

/**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ class PolicyManagerImpl : public PolicyManager {
const std::vector<std::string> GetAppRequestSubTypes(
const std::string& policy_app_id) const OVERRIDE;

/**
* @brief Gets copy of current policy table data
* @return policy_table as json object
*/
Json::Value GetPolicyTableData() const OVERRIDE;

/**
* @brief Get a list of enabled cloud applications
* @param enabled_apps List filled with the policy app id of each enabled
Expand Down
109 changes: 95 additions & 14 deletions src/components/policy/policy_external/src/cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "policy/cache_manager.h"

#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <cmath>
#include <ctime>
#include <functional>
Expand Down Expand Up @@ -738,6 +739,34 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
pt_->policy_table.consumer_friendly_messages.assign_if_valid(
update_pt.policy_table.consumer_friendly_messages);

pt_->policy_table.module_config.endpoint_properties =
update_pt.policy_table.module_config.endpoint_properties;

// Apply update for vehicle data
if (update_pt.policy_table.vehicle_data.is_initialized()) {
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 =
rpc::Optional<policy_table::VehicleDataItems>();
} else {
auto rpc_spec_items =
CollectRPCSpecVDItems(*pt_->policy_table.vehicle_data->schema_items);
auto custom_items = CollectCustomVDItems(
*update_pt.policy_table.vehicle_data->schema_items);
policy_table::VehicleDataItems vd_to_update(rpc_spec_items);
vd_to_update.insert(
vd_to_update.end(), custom_items.begin(), custom_items.end());

pt_->policy_table.vehicle_data->schema_version =
update_pt.policy_table.vehicle_data->schema_version;
pt_->policy_table.vehicle_data->schema_items =
rpc::Optional<policy_table::VehicleDataItems>(vd_to_update);
}
if (update_pt.policy_table.vehicle_data->schema_version.is_initialized() &&
update_pt.policy_table.vehicle_data->schema_items.is_initialized()) {
}
}

ResetCalculatedPermissions();
Backup();

Expand All @@ -748,6 +777,36 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
return true;
}

policy_table::VehicleDataItems CacheManager::CollectRPCSpecVDItems(
const policy_table::VehicleDataItems& vd_items) {
policy_table::VehicleDataItems result_items;
for (auto& item : vd_items) {
const std::string i_name = "VEHICLEDATA_" + std::string(item.name);
const std::string vd_name = boost::to_upper_copy<std::string>(i_name);
const bool is_standart =
policy_table::EnumSchemaItemFactory::IsRPCSpecVehicleDataType(vd_name);
if (is_standart) {
result_items.push_back(item);
}
}
return result_items;
}

policy_table::VehicleDataItems CacheManager::CollectCustomVDItems(
const policy_table::VehicleDataItems& vd_items) {
policy_table::VehicleDataItems result_items;
for (auto& item : vd_items) {
const std::string i_name = "VEHICLEDATA_" + std::string(item.name);
const std::string vd_name = boost::to_upper_copy<std::string>(i_name);
const bool is_standart =
policy_table::EnumSchemaItemFactory::IsRPCSpecVehicleDataType(vd_name);
if (!is_standart) {
result_items.push_back(item);
}
}
return result_items;
}

void CacheManager::GetHMIAppTypeAfterUpdate(
std::map<std::string, StringArray>& app_hmi_types) {
LOG4CXX_AUTO_TRACE(logger_);
Expand Down Expand Up @@ -1217,14 +1276,8 @@ void CacheManager::CheckPermissions(const PTString& app_id,
if (rpc_param.hmi_levels.end() != hmi_iter) {
result.hmi_level_permitted = PermitResult::kRpcAllowed;

policy_table::Parameters::const_iterator params_iter =
rpc_param.parameters->begin();
policy_table::Parameters::const_iterator params_iter_end =
rpc_param.parameters->end();

for (; params_iter != params_iter_end; ++params_iter) {
result.list_of_allowed_params.insert(
policy_table::EnumToJsonString(*params_iter));
for (const auto& param : *rpc_param.parameters) {
result.list_of_allowed_params.insert(std::string(param));
}
}
}
Expand Down Expand Up @@ -1373,6 +1426,10 @@ bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) {
return true;
}

Json::Value CacheManager::GetPolicyTableData() const {
return pt_->policy_table.ToJsonValue();
}

void CacheManager::GetEnabledCloudApps(
std::vector<std::string>& enabled_apps) const {
#if !defined(CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT)
Expand Down Expand Up @@ -1639,11 +1696,19 @@ std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg(

void CacheManager::GetUpdateUrls(const uint32_t service_type,
EndpointUrls& out_end_points) {
std::stringstream service_type_stream;
service_type_stream << (service_type <= 9 ? "0x0" : "0x") << service_type;

const std::string service_type_str = service_type_stream.str();
GetUpdateUrls(service_type_str, out_end_points);
auto find_hexademical =
[service_type](policy_table::ServiceEndpoints::value_type end_point) {
uint32_t decimal;
std::istringstream(end_point.first) >> std::hex >> decimal;
return end_point.first.compare(0, 2, "0x") == 0 &&
decimal == service_type;
};
auto& end_points = pt_->policy_table.module_config.endpoints;
const auto end_point =
std::find_if(end_points.begin(), end_points.end(), find_hexademical);
if (end_point != end_points.end()) {
GetUpdateUrls(end_point->first, out_end_points);
}
}

void CacheManager::GetUpdateUrls(const std::string& service_type,
Expand Down Expand Up @@ -1984,6 +2049,14 @@ std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() {
sync_primitives::AutoLock auto_lock(cache_lock_);
snapshot_->policy_table = pt_->policy_table;

if (pt_->policy_table.vehicle_data.is_initialized()) {
snapshot_->policy_table.vehicle_data =
rpc::Optional<policy_table::VehicleData>();
snapshot_->policy_table.vehicle_data->mark_initialized();
snapshot_->policy_table.vehicle_data->schema_version =
pt_->policy_table.vehicle_data->schema_version;
}

snapshot_->SetPolicyTableType(policy_table::PT_SNAPSHOT);

CheckSnapshotInitialization();
Expand Down Expand Up @@ -2501,6 +2574,8 @@ bool CacheManager::Init(const std::string& file_name,
} else {
rpc::ValidationReport report("policy_table");
snapshot->ReportErrors(&report);
LOG4CXX_DEBUG(logger_,
"Validation report: " << rpc::PrettyFormat(report));
ex_backup_->RemoveDB();
}
} break;
Expand Down Expand Up @@ -2565,7 +2640,6 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
LOG4CXX_FATAL(logger_, "Failed to read policy table source file.");
return false;
}

Json::Value value;
Json::Reader reader(Json::Features::strictMode());
std::string json(json_string.begin(), json_string.end());
Expand Down Expand Up @@ -2904,6 +2978,7 @@ bool CacheManager::MergePreloadPT(const std::string& file_name) {
MergeFG(new_table, current);
MergeAP(new_table, current);
MergeCFM(new_table, current);
MergeVD(new_table, current);
Backup();
}
return true;
Expand Down Expand Up @@ -2971,6 +3046,12 @@ void CacheManager::MergeCFM(const policy_table::PolicyTable& new_pt,
}
}

void CacheManager::MergeVD(const policy_table::PolicyTable& new_pt,
policy_table::PolicyTable& pt) {
LOG4CXX_AUTO_TRACE(logger_);
pt.vehicle_data.assign_if_valid(new_pt.vehicle_data);
}

void CacheManager::InitBackupThread() {
LOG4CXX_AUTO_TRACE(logger_);
backuper_ = new BackgroundBackuper(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ const std::vector<std::string> PolicyManagerImpl::GetAppRequestSubTypes(
return request_subtypes;
}

Json::Value PolicyManagerImpl::GetPolicyTableData() const {
return cache_->GetPolicyTableData();
}

void PolicyManagerImpl::GetEnabledCloudApps(
std::vector<std::string>& enabled_apps) const {
cache_->GetEnabledCloudApps(enabled_apps);
Expand Down
Loading

0 comments on commit 47cfef3

Please sign in to comment.