Skip to content

Commit

Permalink
Fix app activation during pending cloud connection (#3898)
Browse files Browse the repository at this point in the history
* Fix app activation during pending cloud connection

* Apply suggestions from code review

Co-authored-by: Jacob Keeler <jacob.keeler@livioradio.com>

Co-authored-by: Jacob Keeler <jacob.keeler@livioradio.com>
  • Loading branch information
Jack-Byrne and jacobkeeler committed Apr 4, 2022
1 parent cbc9d39 commit b380f48
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class ApplicationManagerImpl
uint32_t hmi_app_id) const OVERRIDE;
ApplicationSharedPtr application_by_policy_id(
const std::string& policy_app_id) const OVERRIDE;
ApplicationSharedPtr pending_application_by_hmi_app(
uint32_t hmi_app_id) const OVERRIDE;
ApplicationSharedPtr pending_application_by_policy_id(
const std::string& policy_app_id) const OVERRIDE;
ApplicationSharedPtr reregister_application_by_policy_id(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ void SDLActivateAppRequest::on_event(const event_engine::Event& event) {
if (event.id() != BasicCommunication_OnAppRegistered) {
return;
}
unsubscribe_from_event(BasicCommunication_OnAppRegistered);

ApplicationSharedPtr pending_app =
application_manager_.pending_application_by_hmi_app(app_id());
if (pending_app) {
SDL_LOG_ERROR("Application is still pending connection: " << app_id());
return;
}

// Have to use HMI app id from event, since HMI app id from original request
// message will be changed after app, initially requested for launch via
Expand All @@ -312,6 +318,8 @@ void SDLActivateAppRequest::on_event(const event_engine::Event& event) {
return;
}

unsubscribe_from_event(BasicCommunication_OnAppRegistered);

auto main_state =
app->CurrentHmiState(mobile_apis::PredefinedWindows::DEFAULT_WINDOW);
if (mobile_apis::HMILevel::INVALID_ENUM == main_state->hmi_level()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,28 @@ TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidAppId_UNSUCCESS) {
MockAppPtr invalid_mock_app;
EXPECT_CALL(app_mngr_, application_by_hmi_app(_))
.WillOnce(Return(invalid_mock_app));
EXPECT_CALL(app_mngr_, pending_application_by_hmi_app(_))
.WillOnce(Return(ApplicationSharedPtr()));

command->on_event(event);
}

TEST_F(SDLActivateAppRequestTest, OnEvent_PendingApp_UNSUCCESS) {
MessageSharedPtr event_msg = CreateMessage();
(*event_msg)[strings::msg_params][strings::application][strings::app_id] =
kAppID;

std::shared_ptr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>());

Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered);
event.set_smart_object(*event_msg);

MockAppPtr mock_app(CreateMockApp());
EXPECT_CALL(app_mngr_, pending_application_by_hmi_app(_))
.WillOnce(Return(mock_app));
EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).Times(0);
EXPECT_CALL(mock_policy_handler_, OnActivateApp(_, _)).Times(0);

command->on_event(event);
}
Expand All @@ -561,6 +583,8 @@ TEST_F(SDLActivateAppRequestTest, OnEvent_SUCCESS) {

MockAppPtr mock_app(CreateMockApp());
EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).WillOnce(Return(mock_app));
EXPECT_CALL(app_mngr_, pending_application_by_hmi_app(_))
.WillOnce(Return(ApplicationSharedPtr()));

auto hmi_state = std::make_shared<am::HmiState>(mock_app, app_mngr_);
hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ ApplicationSharedPtr ApplicationManagerImpl::application_by_policy_id(
return FindApp(accessor, finder);
}

ApplicationSharedPtr ApplicationManagerImpl::pending_application_by_hmi_app(
uint32_t hmi_app_id) const {
HmiAppIdPredicate finder(hmi_app_id);
DataAccessor<AppsWaitRegistrationSet> accessor = pending_applications();
return FindPendingApp(accessor, finder);
}

ApplicationSharedPtr ApplicationManagerImpl::pending_application_by_policy_id(
const std::string& policy_app_id) const {
PolicyAppIdPredicate finder(policy_app_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class ApplicationManager {
virtual ApplicationSharedPtr application_by_policy_id(
const std::string& policy_app_id) const = 0;

virtual ApplicationSharedPtr pending_application_by_hmi_app(
uint32_t hmi_app_id) const = 0;

virtual ApplicationSharedPtr pending_application_by_policy_id(
const std::string& policy_app_id) const = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class MockApplicationManager : public application_manager::ApplicationManager {
MOCK_CONST_METHOD1(application_by_policy_id,
application_manager::ApplicationSharedPtr(
const std::string& policy_app_id));
MOCK_CONST_METHOD1(
pending_application_by_hmi_app,
application_manager::ApplicationSharedPtr(uint32_t hmi_app_id));
MOCK_CONST_METHOD1(pending_application_by_policy_id,
application_manager::ApplicationSharedPtr(
const std::string& policy_app_id));
Expand Down

0 comments on commit b380f48

Please sign in to comment.