Skip to content

Commit

Permalink
Fix CUSTOM_BUTTON subscription logic
Browse files Browse the repository at this point in the history
Was removed subscription to custom button by default.
Also, added check if app is actually subscribed to
CUSTOM_BUTTON like for all other buttons.
  • Loading branch information
AKalinich-Luxoft committed Jul 16, 2021
1 parent 94c770b commit 9e461d0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
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

0 comments on commit 9e461d0

Please sign in to comment.