Skip to content

Commit

Permalink
Revert "reject PTU system request when PTU not in progress (smartdevi…
Browse files Browse the repository at this point in the history
…celink#3853)"

This reverts commit 7a4a4e0.
  • Loading branch information
OlhaVorobiova committed Feb 16, 2022
1 parent 5daea6b commit a48066a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ class PolicyHandler : public PolicyHandlerInterface,
void CacheRetryInfo(const uint32_t app_id = 0,
const std::string url = std::string(),
const std::string snapshot_path = std::string()) OVERRIDE;
#else // EXTERNAL_PROPRIETARY_MODE
void UpdateLastPTUApp(const uint32_t app_id) OVERRIDE;
#endif // EXTERNAL_PROPRIETARY_MODE

uint32_t GetAppIdForSending() const OVERRIDE;
Expand Down Expand Up @@ -723,8 +721,6 @@ class PolicyHandler : public PolicyHandlerInterface,

void StopRetrySequence() OVERRIDE;

bool IsPTUSystemRequestAllowed(const uint32_t app_id) OVERRIDE;

/**
* @brief OnDeviceSwitching Notifies policy manager on device switch event so
* policy permissions should be processed accordingly
Expand Down Expand Up @@ -936,10 +932,10 @@ class PolicyHandler : public PolicyHandlerInterface,
std::shared_ptr<PolicyManager> atomic_policy_manager_;
std::shared_ptr<PolicyEventObserver> event_observer_;
uint32_t last_activated_app_id_;
uint32_t last_ptu_app_id_;

#ifndef EXTERNAL_PROPRIETARY_MODE
// PTU retry information
uint32_t last_ptu_app_id_;
std::string retry_update_url_;
std::string policy_snapshot_path_;
#endif // EXTERNAL_PROPRIETARY_MODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ void OnSystemRequestNotification::Run() {
if (helpers::Compare<RequestType, helpers::EQ, helpers::ONE>(
request_type, RequestType::RT_PROPRIETARY, RequestType::RT_HTTP)) {
policy_handler_.OnSystemRequestReceived();
#ifdef EXTERNAL_PROPRIETARY_MODE
policy_handler_.UpdateLastPTUApp(app->app_id());
#endif
}
SendNotificationToMobile(message_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,16 +580,6 @@ void SystemRequest::Run() {

SDL_LOG_DEBUG("Binary data ok.");

if (mobile_apis::RequestType::PROPRIETARY == request_type ||
mobile_apis::RequestType::HTTP == request_type) {
auto app_id = application->app_id();
if (!policy_handler_.IsPTUSystemRequestAllowed(app_id)) {
SDL_LOG_DEBUG("Rejected PTU SystemRequest from app " << app_id);
SendResponse(false, mobile_apis::Result::REJECTED);
return;
}
}

if (mobile_apis::RequestType::ICON_URL == request_type) {
application_manager_.SetIconFileFromSystemRequest(file_name);
SendResponse(true, mobile_apis::Result::SUCCESS);
Expand Down
34 changes: 8 additions & 26 deletions src/components/application_manager/src/policies/policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,14 @@ PolicyHandler::PolicyHandler(const PolicySettings& settings,
ApplicationManager& application_manager)
: AsyncRunner("PolicyHandler async runner thread")
, last_activated_app_id_(0)
#ifndef EXTERNAL_PROPRIETARY_MODE
, last_ptu_app_id_(0)
#endif // EXTERNAL_PROPRIETARY_MODE
, statistic_manager_impl_(std::make_shared<StatisticManagerImpl>(this))
, settings_(settings)
, application_manager_(application_manager)
, last_registered_policy_app_id_(std::string()) {}
, last_registered_policy_app_id_(std::string()) {
}

PolicyHandler::~PolicyHandler() {}

Expand Down Expand Up @@ -420,31 +423,13 @@ void PolicyHandler::StopRetrySequence() {
SDL_LOG_AUTO_TRACE();
const auto policy_manager = LoadPolicyManager();
POLICY_LIB_CHECK_VOID(policy_manager);
#ifndef EXTERNAL_PROPRIETARY_MODE
// Clear cached PTU app
last_ptu_app_id_ = 0;
#endif // EXTERNAL_PROPRIETARY_MODE
policy_manager->StopRetrySequence();
}

bool PolicyHandler::IsPTUSystemRequestAllowed(const uint32_t app_id) {
SDL_LOG_AUTO_TRACE();
const auto policy_manager = LoadPolicyManager();
POLICY_LIB_CHECK_OR_RETURN(policy_manager, false);

if (policy_manager->GetPolicyTableStatus() != "UPDATING") {
SDL_LOG_DEBUG("PTU received while not UPDATING");
return false;
}

if (app_id != last_ptu_app_id_) {
SDL_LOG_DEBUG(
"PTU received from unexpected application, request was sent to "
<< last_ptu_app_id_);
return false;
}

return true;
}

bool PolicyHandler::ResetPolicyTable() {
SDL_LOG_TRACE("Reset policy table.");
const auto policy_manager = LoadPolicyManager();
Expand Down Expand Up @@ -491,11 +476,6 @@ void PolicyHandler::CacheRetryInfo(const uint32_t app_id,
retry_update_url_ = url;
policy_snapshot_path_ = snapshot_path;
}
#else // EXTERNAL_PROPRIETARY_MODE
void PolicyHandler::UpdateLastPTUApp(const uint32_t app_id) {
SDL_LOG_DEBUG("UpdateLastPTUApp to " << app_id);
last_ptu_app_id_ = app_id;
}
#endif // EXTERNAL_PROPRIETARY_MODE

uint32_t PolicyHandler::GetAppIdForSending() const {
Expand Down Expand Up @@ -1306,8 +1286,10 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
policy_manager->CleanupUnpairedDevices();
SetDaysAfterEpoch();
policy_manager->OnPTUFinished(load_pt_result);
#ifndef EXTERNAL_PROPRIETARY_MODE
// Clean up retry information
last_ptu_app_id_ = 0;
#endif // EXTERNAL_PROPRIETARY_MODE

uint32_t correlation_id = application_manager_.GetNextHMICorrelationID();
event_observer_->subscribe_on_event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ class PolicyHandlerInterface : public VehicleDataItemProvider {
const uint32_t app_id = 0,
const std::string url = std::string(),
const std::string snapshot_path = std::string()) = 0;
#else
virtual void UpdateLastPTUApp(const uint32_t app_id) = 0;
#endif // EXTERNAL_PROPRIETARY_MODE

/**
Expand All @@ -428,8 +426,6 @@ class PolicyHandlerInterface : public VehicleDataItemProvider {

virtual void OnPTInited() = 0;

virtual bool IsPTUSystemRequestAllowed(const uint32_t app_id) = 0;

/**
* @brief Force stops retry sequence timer and resets retry sequence
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
void(const uint32_t app_id,
const std::string url,
const std::string snapshot_path));
#else
MOCK_METHOD1(UpdateLastPTUApp, void(const uint32_t app_id));
#endif
MOCK_CONST_METHOD0(GetAppIdForSending, uint32_t());
MOCK_METHOD1(
Expand All @@ -212,7 +210,6 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
MOCK_METHOD1(OnCertificateUpdated, void(const std::string& certificate_data));
MOCK_METHOD1(OnPTUFinished, void(const bool ptu_result));
MOCK_METHOD0(OnPTInited, void());
MOCK_METHOD1(IsPTUSystemRequestAllowed, bool(const uint32_t app_id));
MOCK_METHOD0(StopRetrySequence, void());
MOCK_METHOD1(OnCertificateDecrypted, void(bool is_succeeded));
MOCK_METHOD0(CanUpdate, bool());
Expand Down

0 comments on commit a48066a

Please sign in to comment.