Skip to content

Commit

Permalink
[SDL 0205] Avoid custom button subscription by default (smartdeviceli…
Browse files Browse the repository at this point in the history
…nk#3744)

* Add SubscribeButtonRequest and SubscribeButtonResponse classes

* unsubscribe buttons implementation (#197)

* Resume button subscriptions

* Remove OnButtonSubscription notification

* Unify approach to result codes processing

* Add shared base class for mobile button notifications

* Revert expired button requests if response was received after timeout

* Fix CUSTOM_BUTTON subscription logic

Was removed subscription to custom button by default.
Also, added check if app is actually subscribed to
CUSTOM_BUTTON like for all other buttons.

* Separate subscription processing for mobile requests and resumption

* Fix affected unit tests

* Return on_event() back to HMI subscription request

* Add unit tests for subscribe and unsubscribe button

* Avoid subscribe to custom button by default

* Address Livio comments

* Address Livio comments

* fixup! Address Livio comments

* Update CUSTOM_BUTTON logic

* Fix tests after merge conflicts

Co-authored-by: Yana Chernysheva <ychernysheva@luxoft.com>
Co-authored-by: Andrii Kalinich <AKalinich@luxoft.com>
Co-authored-by: Olha Vorobiova <olha.vorobiova@dxc.com>
  • Loading branch information
4 people authored Aug 16, 2021
1 parent 04c02ec commit 6cbe18f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/appMain/hmi_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@
"shortPressAvailable": true,
"longPressAvailable": true,
"upDownAvailable": true
},
{
"name" : "CUSTOM_BUTTON",
"longPressAvailable" : true,
"shortPressAvailable" : true,
"upDownAvailable" : true
}
],
"presetBankCapabilities": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ class RegisterAppInterfaceRequest
const std::string& param,
const std::string& backup_value);
/**
* @brief Sends ButtonSubscription notification at start up
* to notify HMI that app subscribed on the custom button by default.
* @brief Sends ButtonSubscription request if approved by hmi_capabilities
*/
void SendSubscribeCustomButtonNotification();
void SendSubscribeCustomButtonRequest();

/**
* @brief IsApplicationSwitched checks whether application is switched
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,11 @@ void RegisterAppInterfaceRequest::Run() {
SendOnAppRegisteredNotificationToHMI(
application, is_resumption_required && !is_resumption_failed_);

// By default app subscribed to CUSTOM_BUTTON
SendSubscribeCustomButtonNotification();
if (CheckHMICapabilities(mobile_apis::ButtonName::CUSTOM_BUTTON)) {
SDL_LOG_DEBUG("CUSTOM_BUTTON available");
SendSubscribeCustomButtonRequest();
}

SendChangeRegistrationOnHMI(application);

if (is_resumption_required) {
Expand Down Expand Up @@ -1461,7 +1464,7 @@ void RegisterAppInterfaceRequest::CheckResponseVehicleTypeParam(
}
}

void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() {
void RegisterAppInterfaceRequest::SendSubscribeCustomButtonRequest() {
SDL_LOG_AUTO_TRACE();
using namespace smart_objects;
SmartObject msg_params = SmartObject(SmartType_Map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,17 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) {
.WillByDefault(
Return(application_manager::HmiInterfaces::HMI_INTERFACE_Buttons));

ON_CALL(mock_hmi_capabilities_, is_ui_cooperating())
.WillByDefault(Return(true));

MessageSharedPtr button_caps_ptr =
CreateMessage(smart_objects::SmartType_Map);
(*button_caps_ptr)[0][am::hmi_response::button_name] =
mobile_apis::ButtonName::CUSTOM_BUTTON;

ON_CALL(mock_hmi_capabilities_, button_capabilities())
.WillByDefault(Return(button_caps_ptr));

EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
Expand Down Expand Up @@ -584,11 +595,6 @@ TEST_F(RegisterAppInterfaceRequestTest,
hmi_apis::FunctionID::BasicCommunication_OnAppRegistered),
_))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
Expand Down Expand Up @@ -848,11 +854,6 @@ TEST_F(RegisterAppInterfaceRequestTest,
hmi_apis::FunctionID::BasicCommunication_OnAppRegistered),
_))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ TEST_F(

// Count of buttons in json file
const size_t btn_length = buttons_capabilities_so.length();
EXPECT_EQ(16ull, btn_length);
for (size_t index = 0; index < btn_length; ++index) {
EXPECT_TRUE(buttons_capabilities_so
[index][rc_rpc_plugin::enums_value::kShortPressAvailable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class HMICapabilities {

/**
* @brief Sets supported Button's capabilities
* @param soft_button_capabilities supported Button's capabilities
* @param button_capabilities supported Button's capabilities
*/
virtual void set_button_capabilities(
const smart_objects::SmartObject& button_capabilities) = 0;
Expand Down

0 comments on commit 6cbe18f

Please sign in to comment.