From c813503877768ae48bb5e49062bebe25291df1a1 Mon Sep 17 00:00:00 2001 From: "Igor Gapchuk (GitHub)" <41586842+IGapchuk@users.noreply.github.com> Date: Fri, 29 May 2020 17:48:51 +0300 Subject: Fix defect: revoked app still be resumed as FULL. (#2546) App was resumed with Full HMI Level when it has been flagged as revoked in the policy table. This PR adds a check that app is not revoked to continue with HMI Level resumption. --- .../src/resumption/resume_ctrl_impl.cc | 10 ++++-- .../application_manager/resumption_data_test.h | 3 +- .../application_manager/test_resumption_data_db.h | 5 ++- .../test/resumption/resume_ctrl_test.cc | 41 ++++++++++++++++++++-- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc index 4930f47d21..2d5f1b6638 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -630,15 +630,19 @@ bool ResumeCtrlImpl::StartAppHmiStateResumption( LOG4CXX_DEBUG(logger_, "No applicable HMI level found for resuming"); return false; } - const bool is_resume_allowed_by_low_voltage = CheckLowVoltageRestrictions(saved_app); const bool is_hmi_level_allowed_by_ign_cycle = CheckIgnCycleRestrictions(saved_app); - const bool restore_hmi_level_allowed = - is_resume_allowed_by_low_voltage && is_hmi_level_allowed_by_ign_cycle; + const bool is_app_revoked = + application_manager_.GetPolicyHandler().IsApplicationRevoked( + application->policy_app_id()); + + const bool restore_hmi_level_allowed = is_resume_allowed_by_low_voltage && + is_hmi_level_allowed_by_ign_cycle && + !is_app_revoked; if (restore_hmi_level_allowed) { LOG4CXX_INFO(logger_, diff --git a/src/components/application_manager/test/include/application_manager/resumption_data_test.h b/src/components/application_manager/test/include/application_manager/resumption_data_test.h index e313427547..dd6529d872 100644 --- a/src/components/application_manager/test/include/application_manager/resumption_data_test.h +++ b/src/components/application_manager/test/include/application_manager/resumption_data_test.h @@ -161,7 +161,8 @@ class ResumptionDataTest : public ::testing::Test { std::shared_ptr window_params_map_lock_ptr_; application_manager_test::MockApplicationManagerSettings mock_application_manager_settings_; - application_manager_test::MockApplicationManager mock_application_manager_; + NiceMock + mock_application_manager_; std::shared_ptr > mock_app_extension_; std::list extensions_; diff --git a/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h b/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h index 3f5802cb5a..e7a8f25261 100644 --- a/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h +++ b/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h @@ -44,13 +44,16 @@ namespace test { namespace components { namespace resumption_test { +using ::testing::NiceMock; + class TestResumptionDataDB : public ResumptionDataDB { public: utils::dbms::SQLDatabase* get_db_handle() { return db(); } - application_manager_test::MockApplicationManager mock_application_manager_; + NiceMock + mock_application_manager_; TestResumptionDataDB(DbStorage db_storage) : ResumptionDataDB(db_storage, mock_application_manager_) {} }; diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index da3cd934e4..b4e5e85376 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -53,6 +53,7 @@ #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_message_helper.h" #include "application_manager/mock_state_controller.h" +#include "application_manager/policies/mock_policy_handler_interface.h" namespace test { namespace components { @@ -203,17 +204,25 @@ class ResumeCtrlTest : public ::testing::Test { return response; } + void SetupIsAppRevoked(const bool is_app_revoked) { + EXPECT_CALL(mock_app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_)); + EXPECT_CALL(mock_policy_handler_, IsApplicationRevoked(_)) + .WillOnce(Return(is_app_revoked)); + } + NiceMock mock_event_dispatcher_; - application_manager_test::MockApplicationManagerSettings + NiceMock mock_application_manager_settings_; NiceMock mock_app_mngr_; std::shared_ptr > mock_app_extension_; - MockStateController mock_state_controller_; + NiceMock mock_state_controller_; std::shared_ptr res_ctrl_; std::shared_ptr > mock_storage_; std::shared_ptr > mock_app_; std::shared_ptr mock_help_prompt_manager_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_; application_manager::ApplicationConstSharedPtr const_app_; const uint32_t kTestAppId_; const std::string kTestPolicyAppId_; @@ -246,7 +255,6 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithGrammarId) { // Check RestoreApplicationData GetInfoFromApp(); - ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(kDefaultTestLevel_)); ON_CALL(*mock_storage_, @@ -933,6 +941,9 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInFull) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -980,6 +991,9 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppHasDeferredResumption) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + mobile_apis::HMILevel::eType app_deferred_level = deferred_level; EXPECT_CALL(*mock_app_, deferred_resumption_hmi_level()) .WillRepeatedly(ReturnPointee(&app_deferred_level)); @@ -1016,6 +1030,9 @@ TEST_F(ResumeCtrlTest, GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(mock_app_mngr_, CheckResumptionRequiredTransportAvailable(_)) .WillOnce(Return(false)); @@ -1061,6 +1078,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(mock_app_mngr_, CheckResumptionRequiredTransportAvailable(_)) .WillOnce(Return(false)); @@ -1210,6 +1230,9 @@ TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1554,6 +1577,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1596,6 +1622,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); @@ -1662,6 +1691,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1704,6 +1736,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); -- cgit v1.2.1