summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/policies/policy_handler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/policies/policy_handler.cc')
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc568
1 files changed, 469 insertions, 99 deletions
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 23f5227667..9336c6199e 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -34,10 +34,11 @@
#include <dlfcn.h>
#include <algorithm>
#include <vector>
+#include <functional>
#include "application_manager/smart_object_keys.h"
#include "application_manager/policies/delegates/app_permission_delegate.h"
-
+#include "policy/status.h"
#include "application_manager/application_manager.h"
#include "application_manager/state_controller.h"
#include "application_manager/message_helper.h"
@@ -112,7 +113,21 @@ const policy::DeviceParams GetDeviceParams(
device_params.device_handle = device_handle;
return device_params;
}
-}
+
+struct HMILevelPredicate
+ : public std::unary_function<ApplicationSharedPtr, bool> {
+ explicit HMILevelPredicate(const mobile_api::HMILevel::eType level)
+ : level_(level) {}
+
+ bool operator()(const ApplicationSharedPtr app) const {
+ return level_ == app->hmi_level() ? true : false;
+ }
+
+ private:
+ mobile_api::HMILevel::eType level_;
+};
+
+} // namespace
#define POLICY_LIB_CHECK(return_value) \
{ \
@@ -134,25 +149,6 @@ const policy::DeviceParams GetDeviceParams(
static const std::string kCerficateFileName = "certificate";
-struct ApplicationListHmiLevelSorter {
- bool operator()(const application_manager::ApplicationSharedPtr& lhs,
- const application_manager::ApplicationSharedPtr& rhs) {
- if (lhs && rhs) {
- mobile_apis::HMILevel::eType lhs_hmi_level = lhs->hmi_level();
- mobile_apis::HMILevel::eType rhs_hmi_level = rhs->hmi_level();
-
- if (lhs_hmi_level == rhs_hmi_level) {
- return lhs->app_id() < rhs->app_id();
- }
- return lhs_hmi_level < rhs_hmi_level;
- }
- return false;
- }
-};
-
-typedef std::set<application_manager::ApplicationSharedPtr,
- ApplicationListHmiLevelSorter> HmiLevelOrderedApplicationList;
-
struct DeactivateApplication {
explicit DeactivateApplication(
const connection_handler::DeviceHandle& device_id,
@@ -182,9 +178,7 @@ struct SDLAllowedNotification {
, state_controller_(state_controller) {}
void operator()(const ApplicationSharedPtr& app) {
- if (!policy_manager_) {
- return;
- }
+ DCHECK_OR_RETURN_VOID(policy_manager_);
if (device_id_ == app->device()) {
std::string hmi_level;
mobile_apis::HMILevel::eType default_mobile_hmi;
@@ -296,6 +290,10 @@ PolicyHandler::PolicyHandler(const PolicySettings& settings,
PolicyHandler::~PolicyHandler() {}
+bool PolicyHandler::PolicyEnabled() const {
+ return get_settings().enable_policy();
+}
+
bool PolicyHandler::LoadPolicyLibrary() {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoWriteLock lock(policy_manager_lock_);
@@ -304,11 +302,11 @@ bool PolicyHandler::LoadPolicyLibrary() {
"System is configured to work without policy "
"functionality.");
policy_manager_.reset();
- return NULL;
+ return false;
}
dl_handle_ = dlopen(kLibrary.c_str(), RTLD_LAZY);
- char* error = dlerror();
+ const char* error = dlerror();
if (!error) {
if (CreateManager()) {
policy_manager_->set_listener(this);
@@ -323,10 +321,6 @@ bool PolicyHandler::LoadPolicyLibrary() {
return policy_manager_.valid();
}
-bool PolicyHandler::PolicyEnabled() const {
- return get_settings().enable_policy();
-}
-
bool PolicyHandler::CreateManager() {
typedef PolicyManager* (*CreateManager)();
typedef void (*DeleteManager)(PolicyManager*);
@@ -355,7 +349,7 @@ bool PolicyHandler::InitPolicyTable() {
// info necessary for policy table
event_observer_->subscribe_on_event(
hmi_apis::FunctionID::BasicCommunication_OnReady);
- const std::string& preloaded_file = get_settings().preloaded_pt_file();
+ std::string preloaded_file = get_settings().preloaded_pt_file();
if (file_system::FileExists(preloaded_file)) {
return policy_manager_->InitPT(preloaded_file, &get_settings());
}
@@ -366,7 +360,7 @@ bool PolicyHandler::InitPolicyTable() {
bool PolicyHandler::ResetPolicyTable() {
LOG4CXX_TRACE(logger_, "Reset policy table.");
POLICY_LIB_CHECK(false);
- const std::string& preloaded_file = get_settings().preloaded_pt_file();
+ std::string preloaded_file = get_settings().preloaded_pt_file();
if (file_system::FileExists(preloaded_file)) {
return policy_manager_->ResetPT(preloaded_file);
}
@@ -381,30 +375,40 @@ bool PolicyHandler::ClearUserConsent() {
}
uint32_t PolicyHandler::GetAppIdForSending() const {
+ LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK(0);
const ApplicationSet& accessor =
application_manager_.applications().GetData();
- HmiLevelOrderedApplicationList app_list(accessor.begin(), accessor.end());
- LOG4CXX_INFO(logger_, "Apps size: " << app_list.size());
+ HMILevelPredicate has_none_level(mobile_api::HMILevel::HMI_NONE);
+ Applications apps_without_none_level;
+ std::copy_if(accessor.begin(),
+ accessor.end(),
+ std::back_inserter(apps_without_none_level),
+ std::not1(has_none_level));
- for (HmiLevelOrderedApplicationList::const_iterator first = app_list.begin();
- first != app_list.end();
- ++first) {
- if ((*first)->IsRegistered()) {
- const uint32_t app_id = (*first)->app_id();
- DeviceParams device_params = GetDeviceParams(
- (*first)->device(),
- application_manager_.connection_handler().get_session_observer());
+ LOG4CXX_DEBUG(logger_,
+ "Number of apps with different from NONE level: "
+ << apps_without_none_level.size());
- if (kDeviceAllowed ==
- policy_manager_->GetUserConsentForDevice(
- device_params.device_mac_address)) {
- return app_id;
- }
- }
+ uint32_t choosen_app_id =
+ ChooseRandomAppForPolicyUpdate(apps_without_none_level);
+
+ if (choosen_app_id) {
+ return choosen_app_id;
}
- return 0;
+
+ Applications apps_with_none_level;
+ std::copy_if(accessor.begin(),
+ accessor.end(),
+ std::back_inserter(apps_with_none_level),
+ has_none_level);
+
+ LOG4CXX_DEBUG(
+ logger_,
+ "Number of apps with NONE level: " << apps_with_none_level.size());
+
+ return ChooseRandomAppForPolicyUpdate(apps_with_none_level);
}
void PolicyHandler::OnAppPermissionConsent(
@@ -480,9 +484,10 @@ void PolicyHandler::GetAvailableApps(std::queue<std::string>& apps) {
}
}
-void PolicyHandler::AddApplication(const std::string& application_id) {
- POLICY_LIB_CHECK_VOID();
- policy_manager_->AddApplication(application_id);
+StatusNotifier PolicyHandler::AddApplication(
+ const std::string& application_id) {
+ POLICY_LIB_CHECK(utils::MakeShared<utils::CallNothing>());
+ return policy_manager_->AddApplication(application_id);
}
void PolicyHandler::AddDevice(const std::string& device_id,
@@ -522,7 +527,8 @@ void PolicyHandler::OnAppPermissionConsentInternal(
return;
}
- sync_primitives::AutoLock lock(app_to_device_link_lock_);
+ LinkAppsToDevice();
+
if (!app_to_device_link_.size()) {
LOG4CXX_WARN(logger_,
"There are no applications previously stored for "
@@ -585,8 +591,18 @@ void PolicyHandler::OnGetUserFriendlyMessage(
uint32_t correlation_id) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
- std::vector<UserFriendlyMessage> result =
+
+#ifdef EXTERNAL_PROPRIETARY_MODE
+ const std::string active_hmi_language =
+ application_manager::MessageHelper::CommonLanguageToString(
+ application_manager_.hmi_capabilities().active_ui_language());
+ const std::vector<UserFriendlyMessage> result =
+ policy_manager_->GetUserFriendlyMessages(
+ message_codes, language, active_hmi_language);
+#else
+ const std::vector<UserFriendlyMessage> result =
policy_manager_->GetUserFriendlyMessages(message_codes, language);
+#endif // EXTERNAL_PROPRIETARY_MODE
// Send response to HMI with gathered data
MessageHelper::SendGetUserFriendlyMessageResponse(
result, correlation_id, application_manager_);
@@ -599,16 +615,7 @@ void PolicyHandler::OnGetListOfPermissions(const uint32_t connection_key,
// If no specific app was passed, get permissions for all currently registered
// applications
if (!connection_key) {
- sync_primitives::AutoLock lock(app_to_device_link_lock_);
- LinkAppToDevice linker(app_to_device_link_, application_manager_);
- const ApplicationSet& accessor =
- application_manager_.applications().GetData();
- ApplicationSetConstIt it_app = accessor.begin();
- ApplicationSetConstIt it_app_end = accessor.end();
-
- // Add all currently registered applications
- std::for_each(it_app, it_app_end, linker);
-
+ LinkAppsToDevice();
PermissionsConsolidator consolidator;
std::vector<policy::FunctionalGroupPermission> group_permissions;
std::map<std::string, std::string>::const_iterator it =
@@ -658,6 +665,76 @@ void PolicyHandler::OnGetListOfPermissions(const uint32_t connection_key,
}
}
+void PolicyHandler::LinkAppsToDevice() {
+ sync_primitives::AutoLock lock(app_to_device_link_lock_);
+ LinkAppToDevice linker(app_to_device_link_, application_manager_);
+ LOG4CXX_DEBUG(logger_, "add links to app. no specific app was passed");
+ {
+ const ApplicationSet& accessor =
+ application_manager_.applications().GetData();
+ if (accessor.empty()) {
+ LOG4CXX_WARN(logger_,
+ "application_manager doesn't have any applications");
+ } else {
+ // Add all currently registered applications
+ std::for_each(accessor.begin(), accessor.end(), linker);
+ }
+ }
+}
+
+bool PolicyHandler::IsAppSuitableForPolicyUpdate(
+ const Applications::value_type value) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ const uint32_t app_id = value->app_id();
+
+ if (!value->IsRegistered()) {
+ LOG4CXX_DEBUG(logger_,
+ "Application " << app_id << " is not marked as registered.");
+ return false;
+ }
+
+ LOG4CXX_DEBUG(logger_,
+ "Application " << app_id << " marked as registered."
+ "Checking its parameters.");
+
+ DeviceParams device_params = GetDeviceParams(
+ value->device(),
+ application_manager_.connection_handler().get_session_observer());
+
+ const bool is_device_allowed = (kDeviceAllowed ==
+ policy_manager_->GetUserConsentForDevice(
+ device_params.device_mac_address));
+
+ LOG4CXX_DEBUG(logger_,
+ "Is device " << device_params.device_mac_address << " allowed "
+ << std::boolalpha << is_device_allowed);
+
+ if (!is_device_allowed) {
+ return false;
+ }
+
+ return true;
+}
+
+uint32_t PolicyHandler::ChooseRandomAppForPolicyUpdate(
+ Applications& app_list) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ std::random_shuffle(app_list.begin(), app_list.end());
+
+ Applications::const_iterator choosen_app = std::find_if(
+ app_list.begin(),
+ app_list.end(),
+ std::bind1st(std::mem_fun(&PolicyHandler::IsAppSuitableForPolicyUpdate),
+ this));
+
+ if (app_list.end() != choosen_app) {
+ return (*choosen_app)->app_id();
+ }
+
+ return 0;
+}
+
void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
@@ -669,6 +746,8 @@ void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) {
void PolicyHandler::OnUpdateStatusChanged(const std::string& status) {
LOG4CXX_AUTO_TRACE(logger_);
+ POLICY_LIB_CHECK_VOID();
+ policy_manager_->SaveUpdateStatusRequired(policy::kUpToDate != status);
MessageHelper::SendOnStatusUpdate(status, application_manager_);
}
@@ -728,6 +807,21 @@ void PolicyHandler::OnVIIsReady() {
void PolicyHandler::OnVehicleDataUpdated(
const smart_objects::SmartObject& message) {
POLICY_LIB_CHECK_VOID();
+#ifdef EXTERNAL_PROPRIETARY_MODE
+ if (!message.keyExists(strings::msg_params)) {
+ LOG4CXX_ERROR(logger_,
+ "Message does not contains mandatory section "
+ << strings::msg_params);
+ return;
+ }
+ if (message[strings::msg_params].keyExists(strings::vin)) {
+ policy_manager_->SetVINValue(
+ message[strings::msg_params][strings::vin].asString());
+ }
+#else
+ LOG4CXX_DEBUG(logger_,
+ "This functionality is not available for not external policy");
+#endif
}
void PolicyHandler::OnPendingPermissionChange(
@@ -875,7 +969,7 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
correlation_id, vehicle_data_args, application_manager_);
} else {
LOG4CXX_WARN(logger_, "Exchange wasn't successful, trying another one.");
- OnPTExchangeNeeded();
+ policy_manager_->ForcePTExchange();
}
return ret;
}
@@ -897,43 +991,102 @@ bool PolicyHandler::UnloadPolicyLibrary() {
return ret;
}
+#ifdef EXTERNAL_PROPRIETARY_MODE
+struct SDLAlowedNotification {
+ SDLAlowedNotification(const connection_handler::DeviceHandle& device_id,
+ PolicyManager* policy_manager,
+ StateController& state_controller)
+ : device_id_(device_id)
+ , policy_manager_(policy_manager)
+ , state_controller_(state_controller) {}
+
+ void operator()(const ApplicationSharedPtr& app) {
+ DCHECK_OR_RETURN_VOID(policy_manager_);
+ if (app->device() == device_id_) {
+ std::string hmi_level;
+ mobile_apis::HMILevel::eType default_mobile_hmi;
+ policy_manager_->GetDefaultHmi(app->policy_app_id(), &hmi_level);
+ if ("BACKGROUND" == hmi_level) {
+ default_mobile_hmi = mobile_apis::HMILevel::HMI_BACKGROUND;
+ } else if ("FULL" == hmi_level) {
+ default_mobile_hmi = mobile_apis::HMILevel::HMI_FULL;
+ } else if ("LIMITED" == hmi_level) {
+ default_mobile_hmi = mobile_apis::HMILevel::HMI_LIMITED;
+ } else if ("NONE" == hmi_level) {
+ default_mobile_hmi = mobile_apis::HMILevel::HMI_NONE;
+ } else {
+ return;
+ }
+ state_controller_.SetRegularState(app, default_mobile_hmi, true);
+ }
+ }
+
+ private:
+ connection_handler::DeviceHandle device_id_;
+ PolicyManager* policy_manager_;
+ StateController& state_controller_;
+};
+#endif // EXTERNAL_PROPRIETARY_MODE
+
void PolicyHandler::OnAllowSDLFunctionalityNotification(
bool is_allowed, const std::string& device_mac) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
using namespace mobile_apis;
- // Device ids, need to be changed
- std::vector<std::string> device_macs;
const bool device_specific = !device_mac.empty();
// Common devices consents change
connection_handler::ConnectionHandler& connection_handler =
application_manager_.connection_handler();
+
if (!device_specific) {
+ // Device ids, need to be changed
+ std::vector<std::string> device_macs;
connection_handler.GetConnectedDevicesMAC(device_macs);
- } else {
- device_macs.push_back(device_mac);
- }
+ std::vector<std::string>::const_iterator it_ids = device_macs.begin();
+ std::vector<std::string>::const_iterator it_ids_end = device_macs.end();
+ for (; it_ids != it_ids_end; ++it_ids) {
+ const std::string device_id = *it_ids;
+
+ if (kDefaultDeviceMacAddress == device_id) {
+ LOG4CXX_WARN(logger_,
+ "Device with id " << device_id << " wasn't found.");
+ continue;
+ }
+ policy_manager_->SetUserConsentForDevice(device_id, is_allowed);
+ uint32_t device_handle = 0;
+ if (!connection_handler.GetDeviceID(device_id, &device_handle)) {
+ LOG4CXX_WARN(logger_,
+ "Device handle with mac " << device_id
+ << " wasn't found.");
+ }
- std::vector<std::string>::const_iterator it_ids = device_macs.begin();
- std::vector<std::string>::const_iterator it_ids_end = device_macs.end();
- for (; it_ids != it_ids_end; ++it_ids) {
- const std::string device_id = *it_ids;
+#ifdef EXTERNAL_PROPRIETARY_MODE
- if (kDefaultDeviceMacAddress == device_id) {
- LOG4CXX_WARN(logger_, "Device with id " << device_id << " wasn't found.");
- return;
- }
- policy_manager_->SetUserConsentForDevice(device_id, is_allowed);
- uint32_t device_handle = 0;
- if (!connection_handler.GetDeviceID(device_mac, &device_handle)) {
- LOG4CXX_WARN(logger_,
- "Device hadle with mac " << device_mac << " wasn't found.");
+ DataAccessor<ApplicationSet> accessor =
+ application_manager_.applications();
+ if (!is_allowed) {
+ std::for_each(
+ accessor.GetData().begin(),
+ accessor.GetData().end(),
+ DeactivateApplication(device_handle,
+ application_manager_.state_controller()));
+ } else {
+ std::for_each(
+ accessor.GetData().begin(),
+ accessor.GetData().end(),
+ SDLAlowedNotification(device_handle,
+ policy_manager_.get(),
+ application_manager_.state_controller()));
+ }
+
+#endif // EXTERNAL_PROPRIETARY_MODE
}
}
// Case, when specific device was changed
+ uint32_t device_handle = 0u;
if (device_specific) {
- uint32_t device_handle = 0;
+ policy_manager_->SetUserConsentForDevice(device_mac, is_allowed);
if (!connection_handler.GetDeviceID(device_mac, &device_handle)) {
LOG4CXX_WARN(logger_,
"Device hadle with mac " << device_mac << " wasn't found.");
@@ -948,6 +1101,37 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification(
pending_device_handles_.erase(it);
}
+
+#ifdef EXTERNAL_PROPRIETARY_MODE
+
+ if (last_activated_app_id_) {
+ ApplicationSharedPtr app =
+ application_manager_.application(last_activated_app_id_);
+
+ if (!app) {
+ LOG4CXX_WARN(logger_,
+ "Application with id '"
+ << last_activated_app_id_
+ << "' not found among registered applications.");
+ return;
+ }
+ if (is_allowed) {
+ // Send HMI status notification to mobile
+ // Put application in full
+ AudioStreamingState::eType state = app->is_audio()
+ ? AudioStreamingState::AUDIBLE
+ : AudioStreamingState::NOT_AUDIBLE;
+
+ application_manager_.state_controller().SetRegularState(
+ app, mobile_apis::HMILevel::HMI_FULL, state, true);
+ last_activated_app_id_ = 0;
+ } else {
+ DeactivateApplication deactivate_notification(
+ device_handle, application_manager_.state_controller());
+ deactivate_notification(app);
+ }
+ }
+#endif // EXTERNAL_PROPRIETARY_MODE
}
void PolicyHandler::OnIgnitionCycleOver() {
@@ -977,8 +1161,44 @@ void PolicyHandler::OnActivateApp(uint32_t connection_key,
}
} else {
permissions = policy_manager_->GetAppPermissionsChanges(policy_app_id);
+#ifdef EXTERNAL_PROPRIETARY_MODE
+ UsageStatistics& usage = app->usage_report();
+
+ usage.RecordAppUserSelection();
+ DeviceParams device_params = GetDeviceParams(
+ app->device(),
+ application_manager_.connection_handler().get_session_observer());
+ permissions.deviceInfo = device_params;
+
+ DeviceConsent consent = policy_manager_->GetUserConsentForDevice(
+ permissions.deviceInfo.device_mac_address);
+ permissions.isSDLAllowed = kDeviceAllowed == consent;
+
+ // According to the SDLAQ-CRS-2794, p.9
+ // 'priority' should be omitted in case when device
+ // is not allowed.
+ if (!permissions.isSDLAllowed) {
+ permissions.priority.clear();
+ last_activated_app_id_ = connection_key;
+ }
+ if (permissions.appRevoked) {
+ usage.RecordRunAttemptsWhileRevoked();
+ }
+
+ // If isSDLAllowed is false, we should provide device params for user
+ // consent
+ if (!permissions.isSDLAllowed) {
+ pending_device_handles_.push_back(permissions.deviceInfo.device_handle);
+ }
+
+ if (permissions.appPermissionsConsentNeeded) {
+ MessageHelper::SendOnAppPermissionsChangedNotification(
+ app->app_id(), permissions, application_manager_);
+ }
+#else // EXTERNAL_PROPRIETARY_MODE
permissions.isSDLAllowed = true;
+#endif // EXTERNAL_PROPRIETARY_MODE
policy_manager_->RemovePendingPermissionChanges(policy_app_id);
}
// If application is revoked it should not be activated
@@ -1091,8 +1311,8 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id,
bool PolicyHandler::SaveSnapshot(const BinaryMessage& pt_string,
std::string& snap_path) {
const std::string& policy_snapshot_file_name =
- settings_.policies_snapshot_file_name();
- const std::string& system_files_path = settings_.system_files_path();
+ get_settings().policies_snapshot_file_name();
+ const std::string& system_files_path = get_settings().system_files_path();
snap_path = system_files_path + '/' + policy_snapshot_file_name;
bool result = false;
@@ -1107,32 +1327,76 @@ bool PolicyHandler::SaveSnapshot(const BinaryMessage& pt_string,
return result;
}
+#ifdef EXTERNAL_PROPRIETARY_MODE
+void PolicyHandler::OnSnapshotCreated(
+ const BinaryMessage& pt_string,
+ const std::vector<int>& retry_delay_seconds,
+ const uint32_t timeout_exchange_ms) {
+ std::string policy_snapshot_full_path;
+ if (SaveSnapshot(pt_string, policy_snapshot_full_path)) {
+ const uint32_t timeout_exchange_s =
+ timeout_exchange_ms / date_time::DateTime::MILLISECONDS_IN_SECOND;
+ MessageHelper::SendPolicyUpdate(policy_snapshot_full_path,
+ timeout_exchange_s,
+ retry_delay_seconds,
+ application_manager_);
+ }
+}
+#else // EXTERNAL_PROPRIETARY_MODE
void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string) {
LOG4CXX_AUTO_TRACE(logger_);
POLICY_LIB_CHECK_VOID();
-#ifdef EXTENDED_POLICY
+#ifdef PROPRIETARY_MODE
std::string policy_snapshot_full_path;
if (!SaveSnapshot(pt_string, policy_snapshot_full_path)) {
LOG4CXX_ERROR(logger_, "Snapshot processing skipped.");
return;
}
MessageHelper::SendPolicyUpdate(policy_snapshot_full_path,
- policy_manager_->TimeoutExchange(),
+ TimeoutExchangeSec(),
policy_manager_->RetrySequenceDelaysSeconds(),
application_manager_);
-#else
+#else // PROPRIETARY_MODE
+ LOG4CXX_ERROR(logger_, "HTTP policy");
EndpointUrls urls;
- policy_manager_->GetServiceUrls("0x07", urls);
+ policy_manager_->GetUpdateUrls("0x07", urls);
if (urls.empty()) {
LOG4CXX_ERROR(logger_, "Service URLs are empty! NOT sending PT to mobile!");
return;
}
- SendMessageToSDK(pt_string, urls.front().url.front());
-#endif
+
+ static size_t current_app = 0;
+ static size_t current_url = 0;
+ if (current_url >= urls.at(current_app).url.size()) {
+ ApplicationSharedPtr app;
+ current_url = 0;
+
+ bool is_default = false;
+ bool is_registered = false;
+ bool has_urls = false;
+ bool valid_app_found = false;
+ do {
+ if (++current_app >= urls.size()) {
+ current_app = 0;
+ }
+ const std::string& app_id = urls.at(current_app).app_id;
+ app = application_manager_.application_by_policy_id(app_id);
+
+ is_default = (app_id == policy::kDefaultId);
+ is_registered = (app && app->IsRegistered());
+ has_urls = !urls.at(current_app).url.empty();
+ valid_app_found = (is_default || (is_registered && has_urls));
+ } while (!valid_app_found);
+ }
+
+ SendMessageToSDK(pt_string, urls.at(current_app).url.at(current_url));
+ current_url++;
+#endif // PROPRIETARY_MODE
// reset update required false
OnUpdateRequestSentToMobile();
}
+#endif // EXTERNAL_PROPRIETARY_MODE
bool PolicyHandler::GetPriority(const std::string& policy_app_id,
std::string* priority) const {
@@ -1175,10 +1439,16 @@ bool PolicyHandler::GetInitialAppData(const std::string& application_id,
application_id, nicknames, app_hmi_types);
}
-void PolicyHandler::GetServiceUrls(const std::string& service_type,
- EndpointUrls& end_points) {
+void PolicyHandler::GetUpdateUrls(const std::string& service_type,
+ EndpointUrls& out_end_points) {
+ POLICY_LIB_CHECK_VOID();
+ policy_manager_->GetUpdateUrls(service_type, out_end_points);
+}
+
+void PolicyHandler::GetUpdateUrls(const uint32_t service_type,
+ EndpointUrls& out_end_points) {
POLICY_LIB_CHECK_VOID();
- policy_manager_->GetServiceUrls(service_type, end_points);
+ policy_manager_->GetUpdateUrls(service_type, out_end_points);
}
std::string PolicyHandler::GetLockScreenIconUrl() const {
@@ -1196,9 +1466,13 @@ uint32_t PolicyHandler::NextRetryTimeout() {
return policy_manager_->NextRetryTimeout();
}
-int PolicyHandler::TimeoutExchange() {
+uint32_t PolicyHandler::TimeoutExchangeSec() {
+ return TimeoutExchangeMSec() / date_time::DateTime::MILLISECONDS_IN_SECOND;
+}
+
+uint32_t PolicyHandler::TimeoutExchangeMSec() {
POLICY_LIB_CHECK(0);
- return policy_manager_->TimeoutExchange();
+ return policy_manager_->TimeoutExchangeMSec();
}
void PolicyHandler::OnExceededTimeout() {
@@ -1292,9 +1566,86 @@ void PolicyHandler::OnUpdateHMIAppType(
(*it)->OnUpdateHMIAppType(app_hmi_types);
}
}
+#ifdef EXTERNAL_PROPRIETARY_MODE
void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) {
LOG4CXX_AUTO_TRACE(logger_);
+ if (certificate_data.empty()) {
+ OnEmptyCertificateArrived();
+ return;
+ }
+
+ const std::string file_name =
+ file_system::GetAbsolutePath(get_settings().app_storage_folder()) + "/" +
+ kCerficateFileName;
+ const bool is_written = file_system::Write(
+ file_name,
+ std::vector<uint8_t>(certificate_data.begin(), certificate_data.end()));
+ LOG4CXX_DEBUG(logger_,
+ "Saving encrypted certificate data: \"" << certificate_data
+ << '"');
+ if (!is_written) {
+ LOG4CXX_ERROR(logger_,
+ "Unable to save encrypted certificate to file " << file_name);
+ return;
+ }
+ LOG4CXX_DEBUG(logger_, "Saved encrypted certificate data" << file_name);
+
+ MessageHelper::SendDecryptCertificateToHMI(file_name, application_manager_);
+}
+
+void PolicyHandler::OnEmptyCertificateArrived() const {
+ LOG4CXX_DEBUG(logger_, "Empty certificate arrived");
+ const std::string empty_certificate;
+ sync_primitives::AutoLock lock(listeners_lock_);
+ std::for_each(
+ listeners_.begin(),
+ listeners_.end(),
+ std::bind2nd(std::mem_fun(&PolicyHandlerObserver::OnCertificateUpdated),
+ empty_certificate));
+}
+
+void PolicyHandler::OnCertificateDecrypted(bool is_succeeded) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ POLICY_LIB_CHECK_VOID();
+
+ const std::string file_name =
+ file_system::GetAbsolutePath(get_settings().app_storage_folder()) + +"/" +
+ kCerficateFileName;
+
+ LOG4CXX_DEBUG(logger_, "Loading certificate data from file " << file_name);
+
+ utils::ScopeGuard file_deleter =
+ utils::MakeGuard(file_system::DeleteFile, file_name);
+ UNUSED(file_deleter);
+
+ if (!is_succeeded) {
+ LOG4CXX_ERROR(logger_, "Couldn't delete file " << file_name);
+ return;
+ }
+
+ std::string certificate_data;
+ if (!file_system::ReadFile(file_name, certificate_data)) {
+ LOG4CXX_ERROR(logger_,
+ "Unable to read certificate from file " << file_name);
+ return;
+ }
+ LOG4CXX_DEBUG(logger_,
+ "Loaded decrypted certificate data: \"" << certificate_data
+ << '"');
+
+ policy_manager_->SetDecryptedCertificate(certificate_data);
+
+ sync_primitives::AutoLock lock(listeners_lock_);
+ std::for_each(
+ listeners_.begin(),
+ listeners_.end(),
+ std::bind2nd(std::mem_fun(&PolicyHandlerObserver::OnCertificateUpdated),
+ certificate_data));
+}
+#else // EXTERNAL_PROPRIETARY_MODE
+void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(listeners_lock_);
HandlersCollection::const_iterator it = listeners_.begin();
for (; it != listeners_.end(); ++it) {
@@ -1302,6 +1653,7 @@ void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) {
observer->OnCertificateUpdated(certificate_data);
}
}
+#endif // EXTERNAL_PROPRIETARY_MODE
bool PolicyHandler::CanUpdate() {
return 0 != GetAppIdForSending();
@@ -1312,6 +1664,17 @@ void PolicyHandler::RemoveDevice(const std::string& device_id) {
POLICY_LIB_CHECK_VOID();
policy_manager_->MarkUnpairedDevice(device_id);
+#ifdef EXTERNAL_PROPRIETARY_MODE
+ connection_handler::DeviceHandle device_uid;
+ if (application_manager_.connection_handler().GetDeviceID(device_id,
+ &device_uid)) {
+ DataAccessor<ApplicationSet> accessor = application_manager_.applications();
+ std::for_each(accessor.GetData().begin(),
+ accessor.GetData().end(),
+ DeactivateApplication(
+ device_uid, application_manager_.state_controller()));
+ }
+#endif // EXTERNAL_PROPRIETARY_MODE
}
bool PolicyHandler::IsApplicationRevoked(const std::string& app_id) {
@@ -1365,7 +1728,7 @@ const std::string PolicyHandler::RemoteAppsUrl() const {
const std::string default_url;
POLICY_LIB_CHECK(default_url);
EndpointUrls endpoints;
- policy_manager_->GetServiceUrls("queryAppsUrl", endpoints);
+ policy_manager_->GetUpdateUrls("queryAppsUrl", endpoints);
if (endpoints.empty() || endpoints[0].url.empty()) {
return default_url;
}
@@ -1373,7 +1736,7 @@ const std::string PolicyHandler::RemoteAppsUrl() const {
return endpoints[0].url[0];
}
-void policy::PolicyHandler::OnAppsSearchStarted() {
+void PolicyHandler::OnAppsSearchStarted() {
POLICY_LIB_CHECK();
policy_manager_->OnAppsSearchStarted();
}
@@ -1424,6 +1787,13 @@ const VehicleInfo policy::PolicyHandler::GetVehicleInfo() const {
return policy_manager_->GetVehicleInfo();
}
+#ifdef EXTERNAL_PROPRIETARY_MODE
+const MetaInfo PolicyHandler::GetMetaInfo() const {
+ POLICY_LIB_CHECK(MetaInfo());
+ return policy_manager_->GetMetaInfo();
+}
+#endif // EXTERNAL_PROPRIETARY_MODE
+
void PolicyHandler::Increment(usage_statistics::GlobalCounterId type) {
POLICY_LIB_CHECK();
policy_manager_->Increment(type);