Skip to content

Commit

Permalink
Merge pull request #205 from LuxoftSDL/fix/sdl_0192_fix_custom_button…
Browse files Browse the repository at this point in the history
…_subscription_logic

Fix CUSTOM_BUTTON subscription logic
  • Loading branch information
AKalinich-Luxoft authored Jul 16, 2021
2 parents 94c770b + e7e1ebf commit f78f0c8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ TYPED_TEST(OnButtonNotificationCommandsTest,
typename TestFixture::MockAppPtr mock_app = this->CreateMockApp();
EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app));

EXPECT_CALL(*mock_app,
IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON))
.WillOnce(Return(true));
EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId))
.WillOnce(Return(false));

Expand Down Expand Up @@ -228,6 +231,9 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) {
ON_CALL(*mock_app, hmi_level(kDefaultWindowId))
.WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL));
EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app));
EXPECT_CALL(*mock_app,
IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON))
.WillOnce(Return(true));
EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId))
.WillOnce(Return(true));
EXPECT_CALL(this->mock_rpc_service_,
Expand Down Expand Up @@ -268,6 +274,10 @@ TYPED_TEST(OnButtonNotificationCommandsTest,
.WillOnce(Return(mobile_apis::HMILevel::HMI_BACKGROUND));

EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app));

EXPECT_CALL(*mock_app,
IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON))
.WillOnce(Return(true));
EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId))
.WillOnce(Return(true));

Expand Down Expand Up @@ -357,23 +367,21 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) {
std::shared_ptr<Notification> command(
this->template CreateCommand<Notification>(notification_msg));

typename TestFixture::MockAppPtr mock_app = this->CreateMockApp();
std::vector<ApplicationSharedPtr> subscribed_apps_list;
subscribed_apps_list.push_back(mock_app);
auto mock_message_helper = am::MockMessageHelper::message_helper_mock();
smart_objects::SmartObjectSPtr msg =
std::make_shared<smart_objects::SmartObject>();
EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _))
.WillRepeatedly(Return(msg));

typename TestFixture::MockAppPtr mock_app = this->CreateMockApp();
EXPECT_CALL(*mock_app, IsSubscribedToButton(kButtonName))
.WillOnce(Return(true));
EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId))
.WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL));

ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true));
ON_CALL(this->app_mngr_, application(kAppId)).WillByDefault(Return(mock_app));

EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName))
.WillOnce(Return(subscribed_apps_list));
EXPECT_CALL(this->mock_rpc_service_,
SendMessageToMobile(
CheckNotificationMessage(TestFixture::kFunctionId), _));
Expand Down
3 changes: 1 addition & 2 deletions src/components/application_manager/src/application_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ ApplicationImpl::ApplicationImpl(
set_name(app_name);

MarkUnregistered();
// subscribe application to custom button by default
SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON);

// load persistent files
LoadPersistentFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ void ButtonNotificationToMobile::HandleCustomButton(
return;
}

if (!app->IsSubscribedToButton(mobile_apis::ButtonName::CUSTOM_BUTTON)) {
SDL_LOG_ERROR("Application " << app->app_id()
<< " is not subscribed on custom buttons");
return;
}

const uint32_t custom_btn_id =
(*message_)[msg_params][hmi_response::custom_button_id].asUInt();

Expand Down Expand Up @@ -111,22 +117,22 @@ void ButtonNotificationToMobile::HandleOKButton(
using namespace application_manager;
SDL_LOG_DEBUG("OK button received");

const auto subscribed_apps = SubscribedApps();
if (app) {
const auto app_ptr =
std::find_if(subscribed_apps.begin(),
subscribed_apps.end(),
[&app](const ApplicationSharedPtr subscribed_app) {
return app->app_id() == subscribed_app->app_id();
});
if (app_ptr != subscribed_apps.end()) {
SDL_LOG_DEBUG(
"Sending button press for this app id: " << (*app_ptr)->app_id());
SendButtonNotification(*app_ptr);
return;
const auto btn_id = static_cast<mobile_apis::ButtonName::eType>(
(*message_)[strings::msg_params][hmi_response::button_name].asInt());

if (app->IsSubscribedToButton(btn_id)) {
SendButtonNotification(app);
} else {
SDL_LOG_ERROR("Application " << app->app_id()
<< " is not subscribed to button "
<< btn_id);
}

return;
}

const auto subscribed_apps = SubscribedApps();
const auto app_ptr =
std::find_if(subscribed_apps.begin(),
subscribed_apps.end(),
Expand Down Expand Up @@ -156,21 +162,22 @@ void ButtonNotificationToMobile::HandleMediaButton(
SDL_LOG_AUTO_TRACE();
using namespace application_manager;

const auto subscribed_apps = SubscribedApps();

if (app) {
const auto app_ptr =
std::find_if(subscribed_apps.begin(),
subscribed_apps.end(),
[&app](const ApplicationSharedPtr subscribed_app) {
return app->app_id() == subscribed_app->app_id();
});
if (app_ptr != subscribed_apps.end()) {
SendButtonNotification(*app_ptr);
return;
const auto btn_id = static_cast<mobile_apis::ButtonName::eType>(
(*message_)[strings::msg_params][hmi_response::button_name].asInt());

if (app->IsSubscribedToButton(btn_id)) {
SendButtonNotification(app);
} else {
SDL_LOG_ERROR("Application " << app->app_id()
<< " is not subscribed to button "
<< btn_id);
}

return;
}

const auto subscribed_apps = SubscribedApps();
const auto app_ptr =
std::find_if(subscribed_apps.begin(),
subscribed_apps.end(),
Expand All @@ -190,7 +197,6 @@ void ButtonNotificationToMobile::HandleMediaButton(

if (app_ptr != subscribed_apps.end()) {
SendButtonNotification(*app_ptr);
return;
} else {
SDL_LOG_ERROR("No application found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,9 @@ TEST_F(ApplicationImplTest, SubscribeToButton_UnsubscribeFromButton) {
EXPECT_FALSE(app_impl->IsSubscribedToButton(ButtonName::PRESET_0));
}

TEST_F(ApplicationImplTest, SubscribeToDefaultButton_UnsubscribeFromButton) {
EXPECT_TRUE(app_impl->IsSubscribedToButton(ButtonName::CUSTOM_BUTTON));
EXPECT_FALSE(app_impl->SubscribeToButton(ButtonName::CUSTOM_BUTTON));
TEST_F(ApplicationImplTest, NotSubscribedToDefaultButton_SubscribeToButton) {
EXPECT_FALSE(app_impl->IsSubscribedToButton(ButtonName::CUSTOM_BUTTON));
EXPECT_TRUE(app_impl->SubscribeToButton(ButtonName::CUSTOM_BUTTON));
}

TEST_F(ApplicationImplTest, SubscribeToSoftButton_UnsubscribeFromSoftButton) {
Expand Down

0 comments on commit f78f0c8

Please sign in to comment.