From 4566d5196109591fd3cc515826ecfc725c95c79b Mon Sep 17 00:00:00 2001 From: "Andriy Byzhynar (GitHub)" Date: Fri, 30 Aug 2019 20:29:54 +0300 Subject: Fixed app activation during resumption (#3001) Fixed application activation/reactivation during resumption process Fixed related unit tests --- .../mobile/register_app_interface_request.cc | 31 +++++++++++----------- .../src/resumption/resume_ctrl_impl.cc | 27 ++++++++++--------- .../test/resumption/resume_ctrl_test.cc | 6 ----- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index 419f1ca0c5..c4bc5cb486 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -801,15 +801,16 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( return; } - bool resumption = + const bool hash_id_present = (*message_)[strings::msg_params].keyExists(strings::hash_id); + const std::string hash_id = + (*message_)[strings::msg_params][strings::hash_id].asString(); + const bool resumption = hash_id_present && !hash_id.empty(); bool need_restore_vr = resumption; - std::string hash_id; std::string add_info; if (resumption) { - hash_id = (*message_)[strings::msg_params][strings::hash_id].asString(); if (!resumer.CheckApplicationHash(application, hash_id)) { LOG4CXX_WARN(logger_, "Hash from RAI does not match to saved resume data."); @@ -823,6 +824,8 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( need_restore_vr = false; } else { add_info = "Resume succeeded."; + application->set_app_data_resumption_allowance(true); + application->set_is_resuming(true); } } if ((mobile_apis::Result::SUCCESS == result_code) && @@ -831,11 +834,9 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( result_code = result_code_; } - // in case application exist in resumption we need to send resumeVrgrammars - if (false == resumption) { - resumption = resumer.IsApplicationSaved(application->policy_app_id(), - application->mac_address()); - } + // In case application exist in resumption we need to send resumeVrgrammars + const bool is_app_saved_in_resumption = resumer.IsApplicationSaved( + application->policy_app_id(), application->mac_address()); // If app is in resuming state // DisplayCapabilitiesBuilder has to collect all the information @@ -843,7 +844,7 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( // to mobile app, even if hash does not match, which means that app data // will not be resumed, notification should be sent for default window as // it will be resumed in any case - if (resumption) { + if (resumption || is_app_saved_in_resumption) { resumer.StartWaitingForDisplayCapabilitiesUpdate(application); } @@ -885,12 +886,12 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( // and HMI level set-up GetPolicyHandler().OnAppRegisteredOnMobile(application->mac_address(), application->policy_app_id()); - if (resumption) { - if (result_code != mobile_apis::Result::RESUME_FAILED) { - resumer.StartResumption(application, hash_id); - } else { - resumer.StartResumptionOnlyHMILevel(application); - } + + if (result_code != mobile_apis::Result::RESUME_FAILED && + application->is_app_data_resumption_allowed()) { + resumer.StartResumption(application, hash_id); + } else if (is_app_saved_in_resumption) { + resumer.StartResumptionOnlyHMILevel(application); } // By default app subscribed to CUSTOM_BUTTON 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 957075150f..0e1840e867 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -359,6 +359,7 @@ void ResumeCtrlImpl::ApplicationResumptiOnTimer() { void ResumeCtrlImpl::OnAppActivated(ApplicationSharedPtr application) { if (is_resumption_active_) { RemoveFromResumption(application->app_id()); + application->set_is_resuming(false); } } @@ -388,12 +389,13 @@ bool ResumeCtrlImpl::SetAppHMIState( SetupDefaultHMILevel(application); return false; } - application->set_is_resuming(true); + application_manager_.state_controller().SetRegularState( application, mobile_apis::PredefinedWindows::DEFAULT_WINDOW, hmi_level); LOG4CXX_INFO(logger_, "Application with policy id " << application->policy_app_id() << " got HMI level " << hmi_level); + return true; } @@ -518,6 +520,8 @@ bool ResumeCtrlImpl::StartResumption(ApplicationSharedPtr application, << " hmi_app_id = " << application->hmi_app_id() << " policy_id = " << application->policy_app_id() << " received hash = " << hash); + application->set_is_resuming(true); + if (!application->is_cloud_app()) { // Default HMI Level is already set before resumption in // ApplicationManager::OnApplicationRegistered, and handling low bandwidth @@ -540,17 +544,18 @@ bool ResumeCtrlImpl::StartResumption(ApplicationSharedPtr application, bool ResumeCtrlImpl::StartResumptionOnlyHMILevel( ApplicationSharedPtr application) { - // sync_primitives::AutoLock lock(resumtion_lock_); LOG4CXX_AUTO_TRACE(logger_); if (!application) { LOG4CXX_WARN(logger_, "Application does not exist."); return false; } + + application->set_is_resuming(true); LOG4CXX_DEBUG(logger_, - "HMI level resumption requested for application id " - << application->app_id() << "with hmi_app_id " - << application->hmi_app_id() << ", policy_app_id " - << application->policy_app_id()); + "HMI level resumption requested for application id: " + << application->app_id() + << " with hmi_app_id: " << application->hmi_app_id() + << ", policy_app_id " << application->policy_app_id()); if (!application->is_cloud_app()) { // Default HMI Level is already set before resumption in // ApplicationManager::OnApplicationRegistered, and handling low bandwidth @@ -563,7 +568,6 @@ bool ResumeCtrlImpl::StartResumptionOnlyHMILevel( bool result = resumption_storage_->GetSavedApplication( application->policy_app_id(), device_mac, saved_app); if (result) { - // sync_primitives::AutoUnlock unlock(lock); AddToResumptionTimerQueue(application->app_id()); } LOG4CXX_INFO(logger_, "StartResumptionOnlyHMILevel::Result = " << result); @@ -599,9 +603,9 @@ bool ResumeCtrlImpl::StartAppHmiStateResumption( DCHECK_OR_RETURN(application, false); smart_objects::SmartObject saved_app; const std::string& device_mac = application->mac_address(); - const bool result = resumption_storage_->GetSavedApplication( + const bool get_saved_app_result = resumption_storage_->GetSavedApplication( application->policy_app_id(), device_mac, saved_app); - if (!result) { + if (!get_saved_app_result) { LOG4CXX_ERROR(logger_, "Application was not saved"); return false; } @@ -626,14 +630,14 @@ bool ResumeCtrlImpl::StartAppHmiStateResumption( if (restore_hmi_level_allowed) { LOG4CXX_INFO(logger_, "Resume application " << application->policy_app_id()); - bool result = RestoreAppHMIState(application); + const bool hmi_state_restore_result = RestoreAppHMIState(application); if (mobile_apis::HMILevel::eType::INVALID_ENUM != application->deferred_resumption_hmi_level()) { // the application has not been fully resumed return false; } RemoveApplicationFromSaved(application); - return result; + return hmi_state_restore_result; } else { LOG4CXX_INFO( logger_, @@ -773,7 +777,6 @@ void ResumeCtrlImpl::StartWaitingForDisplayCapabilitiesUpdate( windows_info = saved_app[strings::windows_info]; } builder.InitBuilder(resume_callback, windows_info); - application->set_is_resuming(true); } void ResumeCtrlImpl::AddFiles(ApplicationSharedPtr application, 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 899fc00846..9f0430a937 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -1098,7 +1098,6 @@ TEST_F(ResumeCtrlTest, RestoreAppHMIState_RestoreHMILevelFull) { ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); const bool res = res_ctrl_->RestoreAppHMIState(mock_app_); EXPECT_TRUE(res); @@ -1204,7 +1203,6 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMINone_WithoutCheckPolicy) { EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultWindowId, kDefaultTestLevel_)) .Times(AtLeast(1)); @@ -1218,7 +1216,6 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMILimited_WithoutCheckPolicy) { GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); @@ -1233,7 +1230,6 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithoutCheckPolicy) { EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)).Times(0); EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); @@ -1249,7 +1245,6 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithPolicy_DevAllowed) { ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); @@ -1265,7 +1260,6 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithPolicy_DevDisallowed) { ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceDisallowed)); - EXPECT_CALL(*mock_app_, set_is_resuming(true)); ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(kDefaultTestLevel_)); EXPECT_CALL(mock_state_controller_, -- cgit v1.2.1