summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcollin <collin+i@collinmcqueen.com>2021-08-12 14:25:51 -0400
committercollin <collin+i@collinmcqueen.com>2021-08-12 14:25:51 -0400
commit036b1851c93bb89375e82786e4a7bd1b3848b89c (patch)
treeff16df6099307faa9ae7a0ef595e0af0c2ab4d9a
parent253280549e45ed726cce9246682fe09263ef5525 (diff)
downloadsdl_core-036b1851c93bb89375e82786e4a7bd1b3848b89c.tar.gz
Squashed commit of the following:
commit ce9fc4455093d4914dfec55a6e5003da3c28fc83 Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Thu Aug 5 18:50:33 2021 -0400 Update CUSTOM_BUTTON logic commit 237562b555dc78322f6c6dd5b9c83ded0226998d Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Thu Aug 5 09:10:59 2021 -0400 fixup! Address Livio comments commit 16142947000f2ed54279306468a6c4cb1594805f Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Wed Aug 4 17:17:17 2021 -0400 Address Livio comments commit daa1060833441f38a7219d8a852c6d44e852e76e Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Tue Jul 27 20:15:06 2021 -0400 Address Livio comments commit a327f0694db958a1925b6526e8d25ce9c86bd735 Author: Olha Vorobiova <olha.vorobiova@dxc.com> Date: Tue Jul 20 16:40:27 2021 +0300 Add unit tests for subscribe and unsubscribe button commit dce94e5d84698f5d85bddbc8b5324518d4c1f9f4 Merge: f78f0c82ea 82703c98bb Author: Andrii Kalinich (GitHub) <AKalinich@luxoft.com> Date: Fri Jul 16 19:12:45 2021 -0400 Merge pull request #206 from LuxoftSDL/impl/sdl_0192_fix_resumption_of_button_subscriptions Separate subscription processing logic for mobile requests and resumption commit 82703c98bb2b68c11bfc642bc976d7b29be416c8 Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Fri Jul 16 15:07:15 2021 -0400 Return on_event() back to HMI subscription request commit f78f0c82ea495376298dae5efda25dde05a7ec7b Merge: 94c770b314 e7e1ebf3ce Author: Andrii Kalinich (GitHub) <AKalinich@luxoft.com> Date: Fri Jul 16 19:00:15 2021 -0400 Merge pull request #205 from LuxoftSDL/fix/sdl_0192_fix_custom_button_subscription_logic Fix CUSTOM_BUTTON subscription logic commit e7e1ebf3ce7b49139f3ddfb77046a642d049294e Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Fri Jul 16 13:02:46 2021 -0400 Fix affected unit tests commit d156a9f0067a61b32323b1e0eae680e488780045 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Fri Jul 16 16:09:27 2021 +0300 Separate subscription processing for mobile requests and resumption commit 9e461d05d2843dedb4a3e3945d907d6e8a376311 Author: Andrii Kalinich <AKalinich@luxoft.com> Date: Fri Jul 16 01:31:05 2021 -0400 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. commit 94c770b314659a33555d81bd47e4c76325c322eb Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Wed Jul 14 15:32:40 2021 +0300 Revert expired button requests if response was received after timeout commit de6c7aac0650d6ac823cd3e6cc0ff4ff9d96eef9 Merge: 0343ea4e9f eaec9b47a5 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Thu Jul 15 15:23:10 2021 +0300 Merge branch 'develop' into feature/sdl_0192_button_subscription_response_from_hmi commit 0343ea4e9f2ef844aa096f76b85719f66eb6db36 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Mon Jul 5 14:46:21 2021 +0300 Add shared base class for mobile button notifications commit 3d7d670476634bf687271dd5a5ebc95b907cab05 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Fri Jul 9 16:13:21 2021 +0300 Unify approach to result codes processing commit e5dfa88fbddd3ec71c05e3e49f68379470e24233 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Thu Jul 8 11:40:13 2021 +0300 Remove OnButtonSubscription notification commit 06dc97859063cfc8a654365db3396a8752cb4f9b Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Wed Jul 7 13:39:12 2021 +0300 Resume button subscriptions commit 4cf9954b46c0496356200ce0d2c4a96ace5e0b6d Author: Vadym Luchko (GitHub) <76956836+VadymLuchko@users.noreply.github.com> Date: Fri Jul 9 14:09:43 2021 +0300 unsubscribe buttons implementation (#197) commit 13045471a9de73b8a37d081efbbe31b1552aa159 Author: Yana Chernysheva <ychernysheva@luxoft.com> Date: Wed Jun 30 17:16:30 2021 +0300 Add SubscribeButtonRequest and SubscribeButtonResponse classes
-rw-r--r--src/components/application_manager/include/application_manager/application.h3
-rw-r--r--src/components/application_manager/include/application_manager/application_manager_impl.h16
-rw-r--r--src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h109
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_impl.h27
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_request_impl.h18
-rw-r--r--src/components/application_manager/include/application_manager/commands/request_from_hmi.h6
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h76
-rw-r--r--src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h11
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc7
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc3
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h87
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h (renamed from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h)43
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h75
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h (renamed from src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc)43
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h12
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h12
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h12
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h25
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc164
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc97
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc125
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc98
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc3
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc3
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc144
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc153
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc8
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc80
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc72
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc22
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc12
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_request_test.cc213
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc145
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc180
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc145
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc50
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc30
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc71
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc27
-rw-r--r--src/components/application_manager/src/application_impl.cc3
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc37
-rw-r--r--src/components/application_manager/src/commands/button_notification_to_mobile.cc219
-rw-r--r--src/components/application_manager/src/commands/command_impl.cc38
-rw-r--r--src/components/application_manager/src/commands/command_request_impl.cc42
-rw-r--r--src/components/application_manager/src/commands/request_from_hmi.cc37
-rw-r--r--src/components/application_manager/src/commands/request_to_hmi.cc34
-rw-r--r--src/components/application_manager/src/helpers/application_helper.cc14
-rw-r--r--src/components/application_manager/src/hmi_interfaces_impl.cc4
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc187
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_processor_impl.cc67
-rw-r--r--src/components/application_manager/test/application_helper_test.cc9
-rw-r--r--src/components/application_manager/test/application_impl_test.cc6
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_message_helper.h31
-rw-r--r--src/components/application_manager/test/mock_message_helper.cc39
-rw-r--r--src/components/application_manager/test/resumption/resume_ctrl_test.cc14
-rw-r--r--src/components/include/application_manager/application_manager.h34
-rw-r--r--src/components/include/test/application_manager/mock_application_manager.h9
-rw-r--r--src/components/interfaces/HMI_API.xml30
62 files changed, 2395 insertions, 894 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h
index 2d7006e19a..86b26f24ef 100644
--- a/src/components/application_manager/include/application_manager/application.h
+++ b/src/components/application_manager/include/application_manager/application.h
@@ -46,6 +46,7 @@
#include "application_manager/hmi_state.h"
#include "application_manager/message.h"
#include "connection_handler/device.h"
+#include "interfaces/HMI_API.h"
#include "interfaces/MOBILE_API.h"
#include "protocol_handler/protocol_handler.h"
#include "smart_objects/smart_object.h"
@@ -106,6 +107,8 @@ struct AppFile {
mobile_apis::FileType::eType file_type;
};
typedef std::map<std::string, AppFile> AppFilesMap;
+typedef std::map<int32_t, hmi_apis::Common_ButtonName::eType>
+ ButtonSubscriptionsMap;
class InitialApplicationData {
public:
virtual ~InitialApplicationData() {}
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h
index 09f2c7d4df..c64ae2bbd2 100644
--- a/src/components/application_manager/include/application_manager/application_manager_impl.h
+++ b/src/components/application_manager/include/application_manager/application_manager_impl.h
@@ -120,6 +120,9 @@ enum VRTTSSessionChanging { kVRSessionChanging = 0, kTTSSessionChanging };
typedef std::map<protocol_handler::ServiceType, std::set<uint32_t> >
ServiceStreamingStatusMap;
+typedef std::map<const int32_t, ExpiredButtonRequestData>
+ ExpiredButtonRequestsMap;
+
struct CommandParametersPermissions;
typedef std::map<std::string, hmi_apis::Common_TransportType::eType>
DeviceTypes;
@@ -1542,6 +1545,16 @@ class ApplicationManagerImpl
static std::vector<std::string> ConvertRejectedParamList(
const std::vector<std::string>& input);
+ void AddExpiredButtonRequest(
+ const uint32_t app_id,
+ const int32_t corr_id,
+ const hmi_apis::Common_ButtonName::eType button_name) OVERRIDE;
+
+ utils::Optional<ExpiredButtonRequestData> GetExpiredButtonRequestData(
+ const int32_t corr_id) const OVERRIDE;
+
+ void DeleteExpiredButtonRequest(const int32_t corr_id) OVERRIDE;
+
private:
const ApplicationManagerSettings& settings_;
/**
@@ -1705,6 +1718,9 @@ class ApplicationManagerImpl
ServiceStreamingStatusMap streaming_application_services_;
sync_primitives::Lock streaming_services_lock_;
+ mutable sync_primitives::Lock expired_button_requests_lock_;
+ mutable ExpiredButtonRequestsMap expired_button_requests_;
+
#ifdef BUILD_TESTS
public:
/**
diff --git a/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h b/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h
new file mode 100644
index 0000000000..66a2683133
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/commands/button_notification_to_mobile.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_
+
+#include "application_manager/application.h"
+#include "command_notification_impl.h"
+#include "interfaces/MOBILE_API.h"
+
+namespace application_manager {
+namespace commands {
+namespace app_mngr = application_manager;
+
+/**
+ * @brief Class is intended to encapsulate shared button notification logic in
+ * base class. Entities defined in this file do not conform to any version of
+ * HMI or mobile API, and exist only to remove duplication in OnButtonPress and
+ * OnButtonEvent notifications.
+ **/
+class ButtonNotificationToMobile
+ : public app_mngr::commands::CommandNotificationImpl {
+ public:
+ /**
+ * @brief ButtonNotificationToMobile class constructor
+ **/
+ ButtonNotificationToMobile(
+ const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handler);
+
+ /**
+ * @brief ButtonNotificationToMobile class destructor
+ **/
+ ~ButtonNotificationToMobile();
+
+ /**
+ * @brief Execute command
+ **/
+ void Run() OVERRIDE;
+
+ protected:
+ virtual void SendButtonNotification(app_mngr::ApplicationSharedPtr app) = 0;
+
+ /**
+ * @brief HandleCustomButton handle event for custom buttons
+ * @param app pointer to application data.
+ **/
+ void HandleCustomButton(app_mngr::ApplicationSharedPtr app);
+
+ /**
+ * @brief HandleOKButton handle event for OK button
+ * @param app pointer to application data.
+ **/
+ void HandleOKButton(app_mngr::ApplicationSharedPtr app);
+
+ /**
+ * @brief HandleMediaButton handle event for media buttons
+ * @param app pointer to application data.
+ **/
+ void HandleMediaButton(app_mngr::ApplicationSharedPtr app);
+
+ /**
+ * @brief DoesParamExist check whether param is exists in msg_params
+ * @param param_name name of parameter to find
+ **/
+ bool DoesParamExist(const std::string& param_name) const;
+
+ /**
+ * @brief SubscribedApps get subscribed apps for btn id received in message
+ * @return Return applications list subscribed to current button
+ **/
+ std::vector<ApplicationSharedPtr> SubscribedApps() const;
+};
+} // namespace commands
+} // namespace application_manager
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_BUTTON_NOTIFICATION_TO_MOBILE_H_
diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h
index 1b4db7e888..6105f7c5d6 100644
--- a/src/components/application_manager/include/application_manager/commands/command_impl.h
+++ b/src/components/application_manager/include/application_manager/commands/command_impl.h
@@ -69,6 +69,23 @@ struct CommandParametersPermissions {
};
namespace commands {
+
+/**
+ * @brief Checks Mobile result code for single RPC
+ * @param result_code contains result code from response to Mobile
+ * @return true if result code complies to successful result codes,
+ * false otherwise.
+ */
+bool IsMobileResultSuccess(const mobile_apis::Result::eType result_code);
+
+/**
+ * @brief Checks HMI result code for single RPC
+ * @param result_code contains result code from HMI response
+ * @return true if result code complies to successful result codes,
+ * false otherwise.
+ */
+bool IsHMIResultSuccess(const hmi_apis::Common_Result::eType result_code);
+
/**
* @brief Class is intended to encapsulate RPC as an object
**/
@@ -183,6 +200,16 @@ class CommandImpl : public Command {
*/
bool CheckSyntax(const std::string& str, bool allow_empty_line = false) const;
+ /**
+ * @brief Checks HMI result code for single RPC
+ * @param result_code contains result code from HMI response
+ * @param interface to check availability
+ * @return true if result code complies to successful result codes,
+ * false otherwise.
+ */
+ bool IsHMIResultSuccess(hmi_apis::Common_Result::eType result_code,
+ HmiInterfaces::InterfaceID interface) const;
+
// members
static const int32_t hmi_protocol_type_;
static const int32_t mobile_protocol_type_;
diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h
index 727863d16d..e2c95a085b 100644
--- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h
+++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h
@@ -206,24 +206,6 @@ class CommandRequestImpl : public CommandImpl,
mobile_apis::Result::eType GetMobileResultCode(
const hmi_apis::Common_Result::eType& hmi_code) const;
- /**
- * @brief Checks Mobile result code for single RPC
- * @param result_code contains result code from response to Mobile
- * @return true if result code complies to successful result codes,
- * false otherwise.
- */
- static bool IsMobileResultSuccess(
- const mobile_apis::Result::eType result_code);
-
- /**
- * @brief Checks HMI result code for single RPC
- * @param result_code contains result code from HMI response
- * @return true if result code complies to successful result codes,
- * false otherwise.
- */
- static bool IsHMIResultSuccess(
- const hmi_apis::Common_Result::eType result_code);
-
protected:
/**
* @brief Checks message permissions and parameters according to policy table
diff --git a/src/components/application_manager/include/application_manager/commands/request_from_hmi.h b/src/components/application_manager/include/application_manager/commands/request_from_hmi.h
index 4464056175..0e03b31e74 100644
--- a/src/components/application_manager/include/application_manager/commands/request_from_hmi.h
+++ b/src/components/application_manager/include/application_manager/commands/request_from_hmi.h
@@ -106,12 +106,6 @@ class RequestFromHMI : public CommandImpl, public event_engine::EventObserver {
const uint32_t hmi_correlation_id,
const hmi_apis::FunctionID::eType& function_id);
- protected:
- bool IsMobileResultSuccess(mobile_apis::Result::eType result_code) const;
-
- bool IsHMIResultSuccess(hmi_apis::Common_Result::eType result_code,
- HmiInterfaces::InterfaceID interface) const;
-
private:
/**
* @brief Fills common parameters for SO
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h
index 2adef91c2e..88200d6593 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -273,52 +273,46 @@ class MessageHelper {
const std::string& path_to_icon, uint32_t app_id);
/**
- * @brief Sends button subscription notification
- * @param app_id Application ID
- * @param button Enum with button name
- * @param is_subscribed true if subscribed, false otherwise
+ * @brief Creates button subscription requests for buttons
+ * that application is subscribed on
+ * @param app application to be subscribed for button
+ * @param button_subscriptions collection of subscribed buttons
+ * @param function_id function ID
* @param app_mngr reference to application manager
+ * @return list of all buttons subscription requests ready to be sent to hmi
+ * @note for every button separate request is created in the list
*/
- static void SendOnButtonSubscriptionNotification(
- const uint32_t app_id,
- const hmi_apis::Common_ButtonName::eType button,
- const bool is_subscribed,
+ static smart_objects::SmartObjectList
+ CreateButtonSubscriptionsHandlingRequestsList(
+ ApplicationConstSharedPtr app,
+ const ButtonSubscriptions& button_subscriptions,
+ const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr);
/**
- * @brief Creates button subscription notification
- * @param app_id Application ID
- * @param button Enum with button name
- * @param is_subscribed true if subscribed, false otherwise
- * @return notification message in SmartObject format
- */
- static smart_objects::SmartObjectSPtr CreateOnButtonSubscriptionNotification(
- const uint32_t app_id,
- const hmi_apis::Common_ButtonName::eType button,
- const bool is_subscribed);
-
- /**
- * @brief Sends button subscription notifications for all buttons
- * that application is subscribed on
+ * @brief Creates button subscription request to mobile
* @param app shared pointer to application instance
- * @param app_mngr reference to application manager
+ * @param source_message source message
+ * @return Smart object with fulfilled request
*/
- static void SendAllOnButtonSubscriptionNotificationsForApp(
- ApplicationConstSharedPtr app, ApplicationManager& app_mngr);
+ static smart_objects::SmartObjectSPtr CreateButtonNotificationToMobile(
+ ApplicationSharedPtr app,
+ const smart_objects::SmartObject& source_message);
/**
- * @brief Creates button subscription notifications for buttons
- * that application is subscribed on
- * @param app shared pointer to application instance
+ * @brief Creates button subscription request to hmi
+ * @param app_id id of application for which request should be created
+ * @param button_name button to be subscribed
+ * @param function_id function ID
* @param app_mngr reference to application manager
- * @param button_subscriptions collection of subscribed buttons
- * @return list of notification messages in SmartObject format
+ * @return Smart object with fulfilled request
*/
- static smart_objects::SmartObjectList
- CreateOnButtonSubscriptionNotificationsForApp(
- ApplicationConstSharedPtr app,
- ApplicationManager& app_mngr,
- const ButtonSubscriptions& button_subscriptions);
+ static smart_objects::SmartObjectSPtr
+ CreateButtonSubscriptionHandlingRequestToHmi(
+ const uint32_t app_id,
+ const hmi_apis::Common_ButtonName::eType button_name,
+ const hmi_apis::FunctionID::eType function_id,
+ ApplicationManager& app_mngr);
static void SendAppDataToHMI(ApplicationConstSharedPtr app,
ApplicationManager& app_man);
@@ -993,18 +987,6 @@ class MessageHelper {
ApplicationManager& app_mngr);
/**
- * @brief SendUnsubscribeButtonNotification sends notification to HMI to
- * remove button subscription for application
- * @param button Button type
- * @param application Application to unsubscribe
- * @param app_mngr Application manager
- */
- static void SendUnsubscribeButtonNotification(
- mobile_apis::ButtonName::eType button,
- ApplicationSharedPtr application,
- ApplicationManager& app_mngr);
-
- /**
* @brief Sends HMI status notification to mobile
* @param application application with changed HMI status
* @param window_id id of affected window
diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h
index c2040852ca..edb3581737 100644
--- a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h
+++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor_impl.h
@@ -367,6 +367,17 @@ class ResumptionDataProcessorImpl
const smart_objects::SmartObject& request,
const smart_objects::SmartObject& response) const;
+ /**
+ * @brief Checks whether SubscribeButton response successful or not and
+ * subscribes application if successful
+ * @param app_id application id
+ * @param request reference to request SO
+ * @param response reference to response SO
+ */
+ void ProcessSubscribeButtonResponse(
+ const uint32_t app_id,
+ const smart_objects::SmartObject& request,
+ const smart_objects::SmartObject& response);
app_mngr::ApplicationManager& application_manager_;
/**
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
index 989c606085..25f389abd0 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
@@ -240,8 +240,8 @@ void ASGetAppServiceDataRequestFromHMI::on_event(
hmi_apis::Common_Result::eType result =
static_cast<hmi_apis::Common_Result::eType>(
event_message[strings::params][hmi_response::code].asInt());
- bool success =
- IsHMIResultSuccess(result, HmiInterfaces::HMI_INTERFACE_AppService);
+ bool success = CommandImpl::IsHMIResultSuccess(
+ result, HmiInterfaces::HMI_INTERFACE_AppService);
if (ValidateResponse(msg_params)) {
SendResponse(success,
correlation_id(),
@@ -263,7 +263,8 @@ void ASGetAppServiceDataRequestFromHMI::on_event(
msg_params[strings::result_code].asInt());
hmi_apis::Common_Result::eType result =
MessageHelper::MobileToHMIResult(mobile_result);
- bool success = IsMobileResultSuccess(mobile_result);
+ bool success =
+ application_manager::commands::IsMobileResultSuccess(mobile_result);
if (ValidateResponse(msg_params)) {
SendResponse(success,
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc
index f5a1aac05c..315d06b85f 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_perform_app_service_interaction_request_from_hmi.cc
@@ -140,7 +140,8 @@ void ASPerformAppServiceInteractionRequestFromHMI::on_event(
msg_params[strings::result_code].asInt());
hmi_apis::Common_Result::eType result =
MessageHelper::MobileToHMIResult(mobile_result);
- bool success = IsMobileResultSuccess(mobile_result);
+ bool success =
+ application_manager::commands::IsMobileResultSuccess(mobile_result);
SendResponse(success,
correlation_id(),
hmi_apis::FunctionID::AppService_PerformAppServiceInteraction,
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
index 719856625d..b0063a327f 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
@@ -96,7 +96,7 @@ void GetAppServiceDataRequest::on_event(
mobile_apis::Result::eType result = static_cast<mobile_apis::Result::eType>(
msg_params[strings::result_code].asInt());
- bool success = IsMobileResultSuccess(result);
+ bool success = application_manager::commands::IsMobileResultSuccess(result);
if (success) {
HandleSubscribe();
}
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
index c303e6d99f..64110a8e23 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
@@ -181,7 +181,7 @@ void PerformAppServiceInteractionRequest::on_event(
: NULL;
mobile_apis::Result::eType result = static_cast<mobile_apis::Result::eType>(
msg_params[strings::result_code].asInt());
- bool success = IsMobileResultSuccess(result);
+ bool success = application_manager::commands::IsMobileResultSuccess(result);
SendResponse(success, result, info, &msg_params);
}
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h
new file mode 100644
index 0000000000..f3e08d0a23
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_request.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_REQUEST_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_REQUEST_H_
+
+#include "application_manager/commands/request_to_hmi.h"
+#include "application_manager/event_engine/event.h"
+#include "utils/macro.h"
+
+namespace sdl_rpc_plugin {
+namespace app_mngr = application_manager;
+
+namespace commands {
+namespace hmi {
+/**
+ * @brief SubscribeButtonRequest command class
+ **/
+class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI,
+ public app_mngr::event_engine::EventObserver {
+ public:
+ /**
+ * @brief SubscribeButtonRequest class constructor
+ * @param message Incoming SmartObject message
+ **/
+ SubscribeButtonRequest(const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle);
+
+ /**
+ * @brief SubscribeButtonRequest class destructor
+ **/
+ ~SubscribeButtonRequest();
+
+ /**
+ * @brief Execute command
+ **/
+ void Run() OVERRIDE;
+
+ void onTimeOut() OVERRIDE;
+
+ void on_event(const application_manager::event_engine::Event& event) OVERRIDE;
+
+ private:
+ app_mngr::ApplicationSharedPtr GetApplicationPtr();
+
+ DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest);
+
+ hmi_apis::Common_ButtonName::eType button_name_;
+};
+
+} // namespace hmi
+} // namespace commands
+} // namespace sdl_rpc_plugin
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_REQUEST_H_
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h
index 0a0a8c3c5d..14c9753d0c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/subscribe_button_response.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Ford Motor Company
+ * Copyright (c) 2021, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,54 +30,49 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_
-#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_
-#include "application_manager/commands/notification_to_hmi.h"
+#include "application_manager/application_manager.h"
+#include "application_manager/commands/response_from_hmi.h"
+#include "utils/macro.h"
namespace sdl_rpc_plugin {
namespace app_mngr = application_manager;
namespace commands {
-
namespace hmi {
-
/**
- * @brief OnButtonSubscriptionNotification command class
+ * @brief SubscribeButtonResponse command class
**/
-class OnButtonSubscriptionNotification
- : public app_mngr::commands::NotificationToHMI {
+class SubscribeButtonResponse : public app_mngr::commands::ResponseFromHMI {
public:
/**
- * @brief OnButtonSubscriptionNotification class constructor
- *
+ * @brief SubscribeButtonResponse class constructor
* @param message Incoming SmartObject message
**/
- OnButtonSubscriptionNotification(
- const app_mngr::commands::MessageSharedPtr& message,
- app_mngr::ApplicationManager& application_manager,
- app_mngr::rpc_service::RPCService& rpc_service,
- app_mngr::HMICapabilities& hmi_capabilities,
- policy::PolicyHandlerInterface& policy_handle);
+ SubscribeButtonResponse(const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle);
/**
- * @brief OnButtonSubscriptionNotification class destructor
+ * @brief SubscribeButtonResponse class destructor
**/
- virtual ~OnButtonSubscriptionNotification();
+ ~SubscribeButtonResponse();
/**
* @brief Execute command
**/
- virtual void Run();
+ void Run() OVERRIDE;
private:
- DISALLOW_COPY_AND_ASSIGN(OnButtonSubscriptionNotification);
+ DISALLOW_COPY_AND_ASSIGN(SubscribeButtonResponse);
};
} // namespace hmi
-
} // namespace commands
-
} // namespace sdl_rpc_plugin
-#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_BUTTON_SUBSCRIPTION_NOTIFICATION_H_
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_SUBSCRIBE_BUTTON_RESPONSE_H_
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h
new file mode 100644
index 0000000000..b377a536cb
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_
+
+#include "application_manager/commands/request_to_hmi.h"
+#include "application_manager/event_engine/event.h"
+#include "utils/macro.h"
+
+namespace sdl_rpc_plugin {
+namespace app_mngr = application_manager;
+
+namespace commands {
+
+namespace hmi {
+
+class UnsubscribeButtonRequest : public app_mngr::commands::RequestToHMI,
+ public app_mngr::event_engine::EventObserver {
+ public:
+ UnsubscribeButtonRequest(const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle);
+
+ ~UnsubscribeButtonRequest();
+
+ void Run() OVERRIDE;
+
+ void onTimeOut() OVERRIDE;
+
+ void on_event(const application_manager::event_engine::Event& event) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonRequest);
+
+ hmi_apis::Common_ButtonName::eType button_name_;
+};
+
+} // namespace hmi
+} // namespace commands
+
+} // namespace sdl_rpc_plugin
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_REQUEST_H_ \ No newline at end of file
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h
index c8d36407b8..5697fa0584 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_button_subscription_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Ford Motor Company
+ * Copyright (c) 2021, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,39 +30,40 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h"
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_
+
+#include "application_manager/application_manager.h"
+#include "application_manager/commands/response_from_hmi.h"
+#include "utils/macro.h"
namespace sdl_rpc_plugin {
-using namespace application_manager;
+namespace app_mngr = application_manager;
namespace commands {
namespace hmi {
-SDL_CREATE_LOG_VARIABLE("Commands")
-
-OnButtonSubscriptionNotification::OnButtonSubscriptionNotification(
- const application_manager::commands::MessageSharedPtr& message,
- ApplicationManager& application_manager,
- rpc_service::RPCService& rpc_service,
- HMICapabilities& hmi_capabilities,
- policy::PolicyHandlerInterface& policy_handle)
- : NotificationToHMI(message,
- application_manager,
- rpc_service,
- hmi_capabilities,
- policy_handle) {}
+class UnsubscribeButtonResponse : public app_mngr::commands::ResponseFromHMI {
+ public:
+ UnsubscribeButtonResponse(const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle);
-OnButtonSubscriptionNotification::~OnButtonSubscriptionNotification() {}
+ ~UnsubscribeButtonResponse();
-void OnButtonSubscriptionNotification::Run() {
- SDL_LOG_AUTO_TRACE();
+ void Run() OVERRIDE;
- SendNotification();
-}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonResponse);
+};
} // namespace hmi
} // namespace commands
} // namespace sdl_rpc_plugin
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_UNSUBSCRIBE_BUTTON_RESPONSE_H_
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h
index afde9bac92..f1ca0f546c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_event_notification.h
@@ -35,6 +35,7 @@
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_BUTTON_EVENT_NOTIFICATION_H_
#include "application_manager/application.h"
+#include "application_manager/commands/button_notification_to_mobile.h"
#include "application_manager/commands/command_notification_impl.h"
#include "utils/macro.h"
@@ -50,7 +51,7 @@ namespace mobile {
* to mobile device that some button was pressed on HMI.
**/
class OnButtonEventNotification
- : public app_mngr::commands::CommandNotificationImpl {
+ : public app_mngr::commands::ButtonNotificationToMobile {
public:
/**
* @brief OnButtonEventNotification class constructor
@@ -68,18 +69,13 @@ class OnButtonEventNotification
**/
virtual ~OnButtonEventNotification();
- /**
- * @brief Execute command
- **/
- virtual void Run();
-
- private:
+ protected:
/*
* @brief Sends button event notification to mobile device
*
* @param app Application to receive notification
*/
- void SendButtonEvent(app_mngr::ApplicationConstSharedPtr app);
+ void SendButtonNotification(app_mngr::ApplicationSharedPtr app) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(OnButtonEventNotification);
};
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h
index 57fda49be7..89f5d48f1a 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/on_button_press_notification.h
@@ -35,6 +35,7 @@
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_ON_BUTTON_PRESS_NOTIFICATION_H_
#include "application_manager/application.h"
+#include "application_manager/commands/button_notification_to_mobile.h"
#include "application_manager/commands/command_notification_impl.h"
#include "utils/macro.h"
@@ -50,7 +51,7 @@ namespace mobile {
* to mobile device that some button was pressed on HMI.
**/
class OnButtonPressNotification
- : public app_mngr::commands::CommandNotificationImpl {
+ : public app_mngr::commands::ButtonNotificationToMobile {
public:
/**
* @brief OnButtonPressNotification class constructor
@@ -66,12 +67,7 @@ class OnButtonPressNotification
/**
* @brief OnButtonEventCommand class destructor
**/
- virtual ~OnButtonPressNotification();
-
- /**
- * @brief Execute command
- **/
- virtual void Run();
+ ~OnButtonPressNotification();
private:
/*
@@ -79,7 +75,7 @@ class OnButtonPressNotification
*
* @param app Application to receive notification
*/
- void SendButtonPress(app_mngr::ApplicationConstSharedPtr app);
+ void SendButtonNotification(app_mngr::ApplicationSharedPtr app) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(OnButtonPressNotification);
};
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h
index 2b9887daad..ecb390095e 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/subscribe_button_request.h
@@ -74,6 +74,12 @@ class SubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl {
*/
bool Init() FINAL;
+ /**
+ * @brief Interface method that is called whenever new event received
+ * @param event The received event
+ */
+ void on_event(const app_mngr::event_engine::Event& event) FINAL;
+
private:
/**
* @brief Checks if button subscription allowed. In case non-media
@@ -88,12 +94,6 @@ class SubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl {
bool IsSubscriptionAllowed(app_mngr::ApplicationSharedPtr app,
const mobile_apis::ButtonName::eType btn_id);
- /**
- * @brief Sends ButtonSubscription notification
- * to notify HMI that app subscribed on the button.
- */
- void SendSubscribeButtonNotification();
-
DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest);
};
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h
index 51c10642cf..5adecb4d7a 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h
@@ -42,44 +42,23 @@ namespace app_mngr = application_manager;
namespace commands {
-/**
- * @brief UnsubscribeButtonRequest command class
- **/
class UnsubscribeButtonRequest : public app_mngr::commands::CommandRequestImpl {
public:
- /**
- * @brief UnsubscribeButtonRequest class constructor
- *
- * @param message Incoming SmartObject message
- **/
UnsubscribeButtonRequest(const app_mngr::commands::MessageSharedPtr& message,
app_mngr::ApplicationManager& application_manager,
app_mngr::rpc_service::RPCService& rpc_service,
app_mngr::HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler);
- /**
- * @brief UnsubscribeButtonRequest class destructor
- **/
~UnsubscribeButtonRequest() FINAL;
- /**
- * @brief Execute command
- **/
void Run() FINAL;
- /**
- * @brief Init sets hash update mode for request
- */
bool Init() FINAL;
- private:
- /**
- * @brief Sends ButtonSubscription notification
- * to notify HMI that app unsubscribed from the button.
- */
- void SendUnsubscribeButtonNotification();
+ void on_event(const app_mngr::event_engine::Event& event) FINAL;
+ private:
DISALLOW_COPY_AND_ASSIGN(UnsubscribeButtonRequest);
};
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc
new file mode 100644
index 0000000000..b1699534bc
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_request.cc
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sdl_rpc_plugin/commands/hmi/subscribe_button_request.h"
+#include "application_manager/message_helper.h"
+#include "application_manager/resumption/resume_ctrl.h"
+
+namespace sdl_rpc_plugin {
+using namespace application_manager;
+
+namespace commands {
+
+SDL_CREATE_LOG_VARIABLE("Commands")
+
+namespace hmi {
+
+SubscribeButtonRequest::SubscribeButtonRequest(
+ const application_manager::commands::MessageSharedPtr& message,
+ ApplicationManager& application_manager,
+ rpc_service::RPCService& rpc_service,
+ HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle)
+ : RequestToHMI(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handle)
+ , EventObserver(application_manager.event_dispatcher()) {
+ hmi_apis::Common_ButtonName::eType button_name =
+ static_cast<hmi_apis::Common_ButtonName::eType>(
+ (*message_)[app_mngr::strings::msg_params]
+ [app_mngr::strings::button_name]
+ .asInt());
+
+ button_name_ = button_name;
+}
+
+SubscribeButtonRequest::~SubscribeButtonRequest() {}
+
+app_mngr::ApplicationSharedPtr SubscribeButtonRequest::GetApplicationPtr() {
+ const uint32_t app_id =
+ (*message_)[strings::msg_params][strings::app_id].asUInt();
+
+ return application_manager_.application_by_hmi_app(app_id);
+}
+
+void SubscribeButtonRequest::Run() {
+ SDL_LOG_AUTO_TRACE();
+
+ // Specific case when app subscribes to CUSTOM_BUTTON upon registration and no
+ // explicit mobile request exist when response arrives. In this case event
+ // should be catched by HMI request itself.
+ if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) {
+ ApplicationSharedPtr app = GetApplicationPtr();
+ if (app) {
+ // Application should also be subscribed to CUSTOM_BUTTON even before
+ // response is received
+ app->SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON);
+ }
+
+ subscribe_on_event(hmi_apis::FunctionID::Buttons_SubscribeButton,
+ correlation_id());
+ }
+
+ SendRequest();
+}
+
+void SubscribeButtonRequest::on_event(const event_engine::Event& event) {
+ SDL_LOG_AUTO_TRACE();
+ using namespace helpers;
+
+ if (hmi_apis::FunctionID::Buttons_SubscribeButton != event.id()) {
+ SDL_LOG_ERROR("Unexpected event id received: " << event.id());
+ return;
+ }
+
+ unsubscribe_from_event(hmi_apis::FunctionID::Buttons_SubscribeButton);
+
+ const smart_objects::SmartObject& message = event.smart_object();
+ ApplicationSharedPtr app = GetApplicationPtr();
+
+ if (!app) {
+ SDL_LOG_ERROR("NULL pointer.");
+ return;
+ }
+
+ const auto hmi_result = static_cast<hmi_apis::Common_Result::eType>(
+ message[strings::params][hmi_response::code].asInt());
+
+ if (CommandImpl::IsHMIResultSuccess(hmi_result,
+ HmiInterfaces::HMI_INTERFACE_Buttons)) {
+ SDL_LOG_DEBUG("Subscription to "
+ << button_name_ << " was successful. Subscribing internally");
+ app->SubscribeToButton(
+ static_cast<mobile_apis::ButtonName::eType>(button_name_));
+ } else if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) {
+ // SDL should revert subscription in a specific case related to custom
+ // button because it was subscribed when the request is sent to HMI
+ SDL_LOG_ERROR(
+ "Subscription to custom button was failed. Revert the internal "
+ "subscription");
+ app->UnsubscribeFromButton(
+ static_cast<mobile_apis::ButtonName::eType>(button_name_));
+ }
+}
+
+void SubscribeButtonRequest::onTimeOut() {
+ SDL_LOG_AUTO_TRACE();
+
+ application_manager_.AddExpiredButtonRequest(
+ application_id(), correlation_id(), button_name_);
+
+ if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == button_name_) {
+ ApplicationSharedPtr app = GetApplicationPtr();
+
+ if (app) {
+ // SDL should revert subscription in a specific case related to custom
+ // button because it was subscribed when the request is sent to HMI
+ SDL_LOG_ERROR(
+ "Subscription to custom button was timed out. Revert the internal "
+ "subscription");
+ app->UnsubscribeFromButton(
+ static_cast<mobile_apis::ButtonName::eType>(button_name_));
+ }
+ }
+
+ auto& resume_ctrl = application_manager_.resume_controller();
+ resume_ctrl.HandleOnTimeOut(
+ correlation_id(),
+ static_cast<hmi_apis::FunctionID::eType>(function_id()));
+}
+
+} // namespace hmi
+} // namespace commands
+} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc
new file mode 100644
index 0000000000..202cde29c6
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/subscribe_button_response.cc
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "sdl_rpc_plugin/commands/hmi/subscribe_button_response.h"
+#include "application_manager/event_engine/event.h"
+#include "application_manager/message_helper.h"
+
+namespace sdl_rpc_plugin {
+using namespace application_manager;
+namespace commands {
+
+SDL_CREATE_LOG_VARIABLE("Commands")
+
+namespace hmi {
+SubscribeButtonResponse::SubscribeButtonResponse(
+ const application_manager::commands::MessageSharedPtr& message,
+ ApplicationManager& application_manager,
+ rpc_service::RPCService& rpc_service,
+ HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle)
+ : ResponseFromHMI(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handle) {}
+
+SubscribeButtonResponse::~SubscribeButtonResponse() {}
+
+void SubscribeButtonResponse::Run() {
+ SDL_LOG_AUTO_TRACE();
+
+ hmi_apis::Common_Result::eType hmi_result =
+ static_cast<hmi_apis::Common_Result::eType>(
+ (*message_)
+ .getElement(strings::params)
+ .getElement(hmi_response::code)
+ .asInt());
+
+ const auto expired_request_data =
+ application_manager_.GetExpiredButtonRequestData(correlation_id());
+ if (expired_request_data) {
+ const uint32_t app_id = (*expired_request_data).app_id_;
+ const auto button_name = (*expired_request_data).button_name_;
+ application_manager_.DeleteExpiredButtonRequest(correlation_id());
+
+ if (!CommandImpl::IsHMIResultSuccess(
+ hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons)) {
+ return;
+ }
+
+ smart_objects::SmartObjectSPtr msg =
+ MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ app_id,
+ button_name,
+ hmi_apis::FunctionID::Buttons_UnsubscribeButton,
+ application_manager_);
+
+ rpc_service_.SendMessageToHMI(msg);
+ return;
+ }
+
+ event_engine::Event event(hmi_apis::FunctionID::Buttons_SubscribeButton);
+ event.set_smart_object(*message_);
+ event.raise(application_manager_.event_dispatcher());
+}
+
+} // namespace hmi
+} // namespace commands
+} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc
new file mode 100644
index 0000000000..dbebf79018
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_request.cc
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h"
+#include "application_manager/event_engine/event_dispatcher_impl.h"
+#include "application_manager/message_helper.h"
+#include "application_manager/resumption/resume_ctrl.h"
+
+namespace sdl_rpc_plugin {
+using namespace application_manager;
+
+namespace commands {
+SDL_CREATE_LOG_VARIABLE("Commands")
+
+namespace hmi {
+
+UnsubscribeButtonRequest::UnsubscribeButtonRequest(
+ const application_manager::commands::MessageSharedPtr& message,
+ ApplicationManager& application_manager,
+ rpc_service::RPCService& rpc_service,
+ HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle)
+ : RequestToHMI(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handle)
+ , EventObserver(application_manager.event_dispatcher()) {
+ hmi_apis::Common_ButtonName::eType button_name =
+ static_cast<hmi_apis::Common_ButtonName::eType>(
+ (*message_)[app_mngr::strings::msg_params]
+ [app_mngr::strings::button_name]
+ .asInt());
+
+ button_name_ = button_name;
+}
+
+UnsubscribeButtonRequest::~UnsubscribeButtonRequest() {}
+
+void UnsubscribeButtonRequest::Run() {
+ SDL_LOG_AUTO_TRACE();
+
+ subscribe_on_event(hmi_apis::FunctionID::Buttons_UnsubscribeButton,
+ correlation_id());
+ SendRequest();
+}
+
+void UnsubscribeButtonRequest::onTimeOut() {
+ SDL_LOG_AUTO_TRACE();
+
+ application_manager_.AddExpiredButtonRequest(
+ application_id(), correlation_id(), button_name_);
+
+ auto& resume_ctrl = application_manager_.resume_controller();
+ resume_ctrl.HandleOnTimeOut(
+ correlation_id(),
+ static_cast<hmi_apis::FunctionID::eType>(function_id()));
+}
+
+void UnsubscribeButtonRequest::on_event(const event_engine::Event& event) {
+ SDL_LOG_AUTO_TRACE();
+
+ if (hmi_apis::FunctionID::Buttons_UnsubscribeButton != event.id()) {
+ SDL_LOG_ERROR("Unexpected event id received: " << event.id());
+ return;
+ }
+
+ unsubscribe_from_event(hmi_apis::FunctionID::Buttons_UnsubscribeButton);
+
+ ApplicationSharedPtr app =
+ application_manager_.application_by_hmi_app(application_id());
+
+ const smart_objects::SmartObject& message = event.smart_object();
+
+ if (!app) {
+ SDL_LOG_ERROR("NULL pointer.");
+ return;
+ }
+
+ hmi_apis::Common_Result::eType hmi_result =
+ static_cast<hmi_apis::Common_Result::eType>(
+ message[strings::params][hmi_response::code].asInt());
+
+ if (CommandImpl::IsHMIResultSuccess(hmi_result,
+ HmiInterfaces::HMI_INTERFACE_Buttons)) {
+ const mobile_apis::ButtonName::eType btn_id =
+ static_cast<mobile_apis::ButtonName::eType>(
+ (*message_)[strings::msg_params][strings::button_name].asInt());
+ app->UnsubscribeFromButton(
+ static_cast<mobile_apis::ButtonName::eType>(btn_id));
+ }
+}
+
+} // namespace hmi
+} // namespace commands
+} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc
new file mode 100644
index 0000000000..68b3663ca7
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/unsubscribe_button_response.cc
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h"
+#include "application_manager/event_engine/event.h"
+#include "application_manager/message_helper.h"
+
+namespace sdl_rpc_plugin {
+using namespace application_manager;
+namespace commands {
+
+SDL_CREATE_LOG_VARIABLE("Commands")
+
+namespace hmi {
+
+UnsubscribeButtonResponse::UnsubscribeButtonResponse(
+ const application_manager::commands::MessageSharedPtr& message,
+ ApplicationManager& application_manager,
+ rpc_service::RPCService& rpc_service,
+ HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handle)
+ : ResponseFromHMI(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handle) {}
+
+UnsubscribeButtonResponse::~UnsubscribeButtonResponse() {}
+
+void UnsubscribeButtonResponse::Run() {
+ SDL_LOG_AUTO_TRACE();
+
+ hmi_apis::Common_Result::eType hmi_result =
+ static_cast<hmi_apis::Common_Result::eType>(
+ (*message_)
+ .getElement(strings::params)
+ .getElement(hmi_response::code)
+ .asInt());
+
+ const auto expired_request_data =
+ application_manager_.GetExpiredButtonRequestData(correlation_id());
+ if (expired_request_data) {
+ const uint32_t app_id = (*expired_request_data).app_id_;
+ const auto button_name = (*expired_request_data).button_name_;
+ application_manager_.DeleteExpiredButtonRequest(correlation_id());
+
+ if (!CommandImpl::IsHMIResultSuccess(
+ hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons)) {
+ return;
+ }
+
+ smart_objects::SmartObjectSPtr msg =
+ MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ app_id,
+ button_name,
+ hmi_apis::FunctionID::Buttons_SubscribeButton,
+ application_manager_);
+
+ rpc_service_.SendMessageToHMI(msg);
+ return;
+ }
+
+ event_engine::Event event(hmi_apis::FunctionID::Buttons_UnsubscribeButton);
+ event.set_smart_object(*message_);
+ event.raise(application_manager_.event_dispatcher());
+}
+
+} // namespace hmi
+} // namespace commands
+} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc
index 2a0ca4ddb3..8febbf4f60 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_window_request.cc
@@ -218,7 +218,8 @@ void CreateWindowRequest::on_event(const event_engine::Event& event) {
static_cast<hmi_apis::Common_Result::eType>(
response_message[strings::params][hmi_response::code].asInt()));
- const bool is_success = IsMobileResultSuccess(result_code);
+ const bool is_success =
+ app_mngr::commands::IsMobileResultSuccess(result_code);
std::string response_info;
GetInfo(response_message, response_info);
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc
index 05347435d7..b675042d16 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_interaction_choice_set_request.cc
@@ -204,7 +204,7 @@ void DeleteInteractionChoiceSetRequest::
continue;
}
- if (!IsHMIResultSuccess(code)) {
+ if (!application_manager::commands::IsHMIResultSuccess(code)) {
result_code = code;
}
}
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc
index 214a9c2bab..6f36f99c6c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/delete_window_request.cc
@@ -134,7 +134,8 @@ void DeleteWindowRequest::on_event(const event_engine::Event& event) {
static_cast<hmi_apis::Common_Result::eType>(
response_message[strings::params][hmi_response::code].asInt()));
- const bool is_success = IsMobileResultSuccess(result_code);
+ const bool is_success =
+ app_mngr::commands::IsMobileResultSuccess(result_code);
std::string response_info;
GetInfo(response_message, response_info);
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc
index 14787d0a08..234c33214c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_event_notification.cc
@@ -34,6 +34,7 @@
#include "sdl_rpc_plugin/commands/mobile/on_button_event_notification.h"
#include "application_manager/application_impl.h"
+#include "application_manager/message_helper.h"
#include "interfaces/MOBILE_API.h"
namespace sdl_rpc_plugin {
@@ -51,146 +52,23 @@ OnButtonEventNotification::OnButtonEventNotification(
rpc_service::RPCService& rpc_service,
HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler)
- : CommandNotificationImpl(message,
- application_manager,
- rpc_service,
- hmi_capabilities,
- policy_handler) {}
+ : ButtonNotificationToMobile(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handler) {}
OnButtonEventNotification::~OnButtonEventNotification() {}
-void OnButtonEventNotification::Run() {
+void OnButtonEventNotification::SendButtonNotification(
+ ApplicationSharedPtr app) {
SDL_LOG_AUTO_TRACE();
- const uint32_t btn_id = static_cast<uint32_t>(
- (*message_)[strings::msg_params][hmi_response::button_name].asInt());
-
- const bool is_app_id_exists =
- (*message_)[strings::msg_params].keyExists(strings::app_id);
- ApplicationSharedPtr app;
-
- // CUSTOM_BUTTON notification
- if (static_cast<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) {
- // app_id is mandatory for CUSTOM_BUTTON notification
- if (!is_app_id_exists) {
- SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonEvent without app_id.");
- return;
- }
-
- app = application_manager_.application(
- (*message_)[strings::msg_params][strings::app_id].asUInt());
-
- // custom_button_id is mandatory for CUSTOM_BUTTON notification
- if (false == (*message_)[strings::msg_params].keyExists(
- hmi_response::custom_button_id)) {
- SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonEvent without custom_button_id.");
- return;
- }
-
- if (!app) {
- SDL_LOG_ERROR("Application doesn't exist.");
- return;
- }
-
- uint32_t custom_btn_id = 0;
- custom_btn_id =
- (*message_)[strings::msg_params][hmi_response::custom_button_id]
- .asUInt();
-
- if (false == app->IsSubscribedToSoftButton(custom_btn_id)) {
- SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id.");
- return;
- }
-
- const auto window_id = app->GetSoftButtonWindowID(custom_btn_id);
- (*message_)[strings::msg_params][strings::window_id] = window_id;
- const auto window_hmi_level = app->hmi_level(window_id);
- if ((mobile_api::HMILevel::HMI_NONE == window_hmi_level)) {
- SDL_LOG_WARN(
- "CUSTOM_BUTTON OnButtonEvent notification is not allowed in "
- "NONE hmi level");
- return;
- }
-
- SendButtonEvent(app);
- return;
- }
-
- const std::vector<ApplicationSharedPtr>& subscribed_apps =
- application_manager_.applications_by_button(btn_id);
-
- std::vector<ApplicationSharedPtr>::const_iterator it =
- subscribed_apps.begin();
- for (; subscribed_apps.end() != it; ++it) {
- ApplicationSharedPtr subscribed_app = *it;
- if (!subscribed_app) {
- SDL_LOG_WARN("Null pointer to subscribed app.");
- continue;
- }
-
- // Send ButtonEvent notification only in HMI_FULL or HMI_LIMITED mode
- const mobile_apis::HMILevel::eType app_hmi_level =
- subscribed_app->hmi_level(
- mobile_apis::PredefinedWindows::DEFAULT_WINDOW);
- if ((mobile_api::HMILevel::HMI_FULL != app_hmi_level) &&
- (mobile_api::HMILevel::HMI_LIMITED != app_hmi_level)) {
- SDL_LOG_WARN("OnButtonEvent notification is allowed only"
- << "in FULL or LIMITED hmi level");
- continue;
- }
- // if OK button and "app_id" absent send notification only in HMI_FULL mode
- // otherwise send to subscribed apps in limited
- if (is_app_id_exists || hmi_apis::Common_ButtonName::OK != btn_id ||
- subscribed_app->IsFullscreen()) {
- SendButtonEvent(subscribed_app);
- }
- }
-}
-
-void OnButtonEventNotification::SendButtonEvent(ApplicationConstSharedPtr app) {
- if (!app) {
- SDL_LOG_ERROR("OnButtonEvent NULL pointer");
- return;
- }
-
- smart_objects::SmartObjectSPtr on_btn_event =
- std::make_shared<smart_objects::SmartObject>();
-
- if (!on_btn_event) {
- SDL_LOG_ERROR("OnButtonEvent NULL pointer");
- return;
- }
-
- (*on_btn_event)[strings::params][strings::connection_key] = app->app_id();
-
- (*on_btn_event)[strings::params][strings::function_id] =
- static_cast<int32_t>(mobile_apis::FunctionID::eType::OnButtonEventID);
-
- mobile_apis::ButtonName::eType btn_id =
- static_cast<mobile_apis::ButtonName::eType>(
- (*message_)[strings::msg_params][hmi_response::button_name].asInt());
-
- if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE &&
- app->msg_version() < utils::rpc_version_5) {
- btn_id = mobile_apis::ButtonName::OK;
- }
-
- (*on_btn_event)[strings::msg_params][strings::button_name] = btn_id;
- (*on_btn_event)[strings::msg_params][strings::button_event_mode] =
- (*message_)[strings::msg_params][hmi_response::button_mode];
-
- if ((*message_)[strings::msg_params].keyExists(
- hmi_response::custom_button_id)) {
- (*on_btn_event)[strings::msg_params][strings::custom_button_id] =
- (*message_)[strings::msg_params][strings::custom_button_id];
- }
+ (*message_)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::eType::OnButtonEventID;
- if ((*message_)[strings::msg_params].keyExists(strings::window_id)) {
- (*on_btn_event)[strings::msg_params][strings::window_id] =
- (*message_)[strings::msg_params][strings::window_id];
- }
+ message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_);
- message_ = on_btn_event;
SendNotification();
}
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc
index 4444f0d156..90bf618c35 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc
@@ -34,6 +34,7 @@
#include "sdl_rpc_plugin/commands/mobile/on_button_press_notification.h"
#include "application_manager/application_impl.h"
+#include "application_manager/message_helper.h"
#include "interfaces/MOBILE_API.h"
#include "utils/semantic_version.h"
@@ -52,155 +53,23 @@ OnButtonPressNotification::OnButtonPressNotification(
rpc_service::RPCService& rpc_service,
HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler)
- : CommandNotificationImpl(message,
- application_manager,
- rpc_service,
- hmi_capabilities,
- policy_handler) {}
+ : ButtonNotificationToMobile(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handler) {}
OnButtonPressNotification::~OnButtonPressNotification() {}
-void OnButtonPressNotification::Run() {
+void OnButtonPressNotification::SendButtonNotification(
+ ApplicationSharedPtr app) {
SDL_LOG_AUTO_TRACE();
- const uint32_t btn_id = static_cast<uint32_t>(
- (*message_)[strings::msg_params][hmi_response::button_name].asInt());
-
- const bool is_app_id_exists =
- (*message_)[strings::msg_params].keyExists(strings::app_id);
- ApplicationSharedPtr app;
- if (is_app_id_exists) {
- app = application_manager_.application(
- (*message_)[strings::msg_params][strings::app_id].asUInt());
- }
-
- // CUSTOM_BUTTON notification
- if (static_cast<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) {
- // app_id is mandatory for CUSTOM_BUTTON notification
- if (!is_app_id_exists) {
- SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without app_id.");
- return;
- }
-
- // custom_button_id is mandatory for CUSTOM_BUTTON notification
- if (false == (*message_)[strings::msg_params].keyExists(
- hmi_response::custom_button_id)) {
- SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without custom_button_id.");
- return;
- }
-
- if (!app) {
- SDL_LOG_ERROR("Application doesn't exist.");
- return;
- }
-
- uint32_t custom_btn_id = 0;
- custom_btn_id =
- (*message_)[strings::msg_params][hmi_response::custom_button_id]
- .asUInt();
-
- if (false == app->IsSubscribedToSoftButton(custom_btn_id)) {
- SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id.");
- return;
- }
-
- // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode
- const auto window_id = app->GetSoftButtonWindowID(custom_btn_id);
- app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW);
- (*message_)[strings::msg_params][strings::window_id] = window_id;
- const auto window_hmi_level = app->hmi_level(window_id);
- if ((mobile_api::HMILevel::HMI_NONE == window_hmi_level)) {
- SDL_LOG_WARN(
- "CUSTOM_BUTTON OnButtonPress notification is not allowed in "
- "NONE hmi level");
- return;
- }
-
- SendButtonPress(app);
- return;
- }
-
- const std::vector<ApplicationSharedPtr>& subscribed_apps =
- application_manager_.applications_by_button(btn_id);
-
- std::vector<ApplicationSharedPtr>::const_iterator it =
- subscribed_apps.begin();
- for (; subscribed_apps.end() != it; ++it) {
- ApplicationSharedPtr subscribed_app = *it;
- if (!subscribed_app) {
- SDL_LOG_WARN("Null pointer to subscribed app.");
- continue;
- }
-
- // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode
- const mobile_apis::HMILevel::eType app_hmi_level =
- subscribed_app->hmi_level(
- mobile_apis::PredefinedWindows::DEFAULT_WINDOW);
- if ((mobile_api::HMILevel::HMI_FULL != app_hmi_level) &&
- (mobile_api::HMILevel::HMI_LIMITED != app_hmi_level)) {
- SDL_LOG_WARN("OnButtonPress notification is allowed only "
- << "in FULL or LIMITED hmi level");
- continue;
- }
- // if "appID" is present, send it to named app only if its FULL or
- // LIMITED
- if (app.use_count() != 0) {
- if (app->app_id() == subscribed_app->app_id()) {
- SendButtonPress(subscribed_app);
- }
- } else if (hmi_apis::Common_ButtonName::OK != btn_id ||
- subscribed_app->IsFullscreen()) {
- // if No "appID" and OK button - send it FULL apps only.
- // if not OK button, send to LIMITED subscribed apps
- SendButtonPress(subscribed_app);
- }
- }
-}
-
-void OnButtonPressNotification::SendButtonPress(ApplicationConstSharedPtr app) {
- if (!app) {
- SDL_LOG_ERROR("OnButtonPress NULL pointer");
- return;
- }
-
- smart_objects::SmartObjectSPtr on_btn_press =
- std::make_shared<smart_objects::SmartObject>();
-
- if (!on_btn_press) {
- SDL_LOG_ERROR("OnButtonPress NULL pointer");
- return;
- }
-
- (*on_btn_press)[strings::params][strings::connection_key] = app->app_id();
-
- (*on_btn_press)[strings::params][strings::function_id] =
- static_cast<int32_t>(mobile_apis::FunctionID::eType::OnButtonPressID);
-
- mobile_apis::ButtonName::eType btn_id =
- static_cast<mobile_apis::ButtonName::eType>(
- (*message_)[strings::msg_params][hmi_response::button_name].asInt());
-
- if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE &&
- app->msg_version() < utils::rpc_version_5) {
- btn_id = mobile_apis::ButtonName::OK;
- }
-
- (*on_btn_press)[strings::msg_params][strings::button_name] = btn_id;
- (*on_btn_press)[strings::msg_params][strings::button_press_mode] =
- (*message_)[strings::msg_params][hmi_response::button_mode];
-
- if ((*message_)[strings::msg_params].keyExists(
- hmi_response::custom_button_id)) {
- (*on_btn_press)[strings::msg_params][strings::custom_button_id] =
- (*message_)[strings::msg_params][strings::custom_button_id];
- }
+ (*message_)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::eType::OnButtonPressID;
- if ((*message_)[strings::msg_params].keyExists(strings::window_id)) {
- (*on_btn_press)[strings::msg_params][strings::window_id] =
- (*message_)[strings::msg_params][strings::window_id];
- }
+ message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_);
- message_ = on_btn_press;
SendNotification();
}
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 c095081f2a..a43603294a 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
@@ -1462,13 +1462,13 @@ void RegisterAppInterfaceRequest::CheckResponseVehicleTypeParam(
}
void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() {
+ SDL_LOG_AUTO_TRACE();
using namespace smart_objects;
SmartObject msg_params = SmartObject(SmartType_Map);
msg_params[strings::app_id] = connection_key();
- msg_params[strings::name] = hmi_apis::Common_ButtonName::CUSTOM_BUTTON;
- msg_params[strings::is_suscribed] = true;
- CreateHMINotification(hmi_apis::FunctionID::Buttons_OnButtonSubscription,
- msg_params);
+ msg_params[strings::button_name] = hmi_apis::Common_ButtonName::CUSTOM_BUTTON;
+ SendHMIRequest(
+ hmi_apis::FunctionID::Buttons_SubscribeButton, &msg_params, false);
}
bool RegisterAppInterfaceRequest::IsApplicationSwitched() {
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc
index 42cb3c60c9..723a1ececa 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc
@@ -32,6 +32,7 @@
*/
#include "sdl_rpc_plugin/commands/mobile/subscribe_button_request.h"
+#include "application_manager/message_helper.h"
#include "utils/semantic_version.h"
namespace sdl_rpc_plugin {
@@ -104,11 +105,11 @@ void SubscribeButtonRequest::Run() {
return;
}
- app->SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(btn_id));
- SendSubscribeButtonNotification();
-
- const bool is_succeeded = true;
- SendResponse(is_succeeded, mobile_apis::Result::SUCCESS);
+ (*message_)[str::msg_params][str::app_id] = app->app_id();
+ StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons);
+ SendHMIRequest(hmi_apis::FunctionID::Buttons_SubscribeButton,
+ &(*message_)[app_mngr::strings::msg_params],
+ true);
}
bool SubscribeButtonRequest::Init() {
@@ -116,6 +117,59 @@ bool SubscribeButtonRequest::Init() {
return true;
}
+void SubscribeButtonRequest::on_event(const event_engine::Event& event) {
+ SDL_LOG_AUTO_TRACE();
+
+ const smart_objects::SmartObject& message = event.smart_object();
+
+ if (hmi_apis::FunctionID::Buttons_SubscribeButton != event.id()) {
+ SDL_LOG_ERROR("Received unknown event.");
+ return;
+ }
+ EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons);
+ ApplicationSharedPtr app =
+ application_manager_.application(CommandRequestImpl::connection_key());
+
+ if (!app) {
+ SDL_LOG_ERROR("NULL pointer.");
+ return;
+ }
+
+ hmi_apis::Common_Result::eType hmi_result =
+ static_cast<hmi_apis::Common_Result::eType>(
+ message[strings::params][hmi_response::code].asInt());
+ std::string response_info;
+ GetInfo(message, response_info);
+ const bool result = PrepareResultForMobileResponse(
+ hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons);
+
+ if (result) {
+ const auto btn_id = static_cast<mobile_apis::ButtonName::eType>(
+ (*message_)[str::msg_params][str::button_name].asInt());
+ app->SubscribeToButton(btn_id);
+ }
+ mobile_apis::Result::eType result_code =
+ MessageHelper::HMIToMobileResult(hmi_result);
+
+ SendResponse(result,
+ result_code,
+ response_info.empty() ? nullptr : response_info.c_str(),
+ &(message[strings::msg_params]));
+}
+
+bool IsPresetButton(const mobile_apis::ButtonName::eType btn_id) {
+ return (mobile_apis::ButtonName::PRESET_0 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_1 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_2 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_3 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_4 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_5 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_6 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_7 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_8 == btn_id) ||
+ (mobile_apis::ButtonName::PRESET_9 == btn_id);
+}
+
bool SubscribeButtonRequest::IsSubscriptionAllowed(
ApplicationSharedPtr app, mobile_apis::ButtonName::eType btn_id) {
if (!app->is_media_application() &&
@@ -123,7 +177,8 @@ bool SubscribeButtonRequest::IsSubscriptionAllowed(
(mobile_apis::ButtonName::SEEKLEFT == btn_id) ||
(mobile_apis::ButtonName::SEEKRIGHT == btn_id) ||
(mobile_apis::ButtonName::TUNEUP == btn_id) ||
- (mobile_apis::ButtonName::TUNEDOWN == btn_id))) {
+ (mobile_apis::ButtonName::TUNEDOWN == btn_id) ||
+ IsPresetButton(btn_id))) {
return false;
}
@@ -149,19 +204,6 @@ bool SubscribeButtonRequest::IsSubscriptionAllowed(
return true;
}
-void SubscribeButtonRequest::SendSubscribeButtonNotification() {
- using namespace smart_objects;
- using namespace hmi_apis;
-
- // send OnButtonSubscription notification
- SmartObject msg_params = SmartObject(SmartType_Map);
- msg_params[strings::app_id] = connection_key();
- msg_params[strings::name] = static_cast<Common_ButtonName::eType>(
- (*message_)[strings::msg_params][strings::button_name].asUInt());
- msg_params[strings::is_suscribed] = true;
- CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params);
-}
-
} // namespace commands
} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc
index 69f85568eb..09de35773a 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/unsubscribe_button_request.cc
@@ -1,6 +1,5 @@
/*
-
- Copyright (c) 2018, Ford Motor Company
+ Copyright (c) 2021, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,6 +33,8 @@
#include "sdl_rpc_plugin/commands/mobile/unsubscribe_button_request.h"
#include "application_manager/application_impl.h"
+#include "application_manager/message_helper.h"
+#include "utils/helpers.h"
#include "utils/semantic_version.h"
namespace sdl_rpc_plugin {
@@ -93,15 +94,59 @@ void UnsubscribeButtonRequest::Run() {
return;
}
- if (!app->UnsubscribeFromButton(
- static_cast<mobile_apis::ButtonName::eType>(btn_id))) {
- SDL_LOG_ERROR("App doesn't subscribe to button " << btn_id);
+ if (!app->IsSubscribedToButton(btn_id)) {
+ SDL_LOG_ERROR("App is not subscribed to button " << btn_id);
+ SendResponse(false, mobile_apis::Result::IGNORED);
+ return;
+ }
+
+ if (mobile_apis::ButtonName::CUSTOM_BUTTON == btn_id) {
+ SDL_LOG_ERROR("App cannot unsubscribe from CUSTOM_BUTTON");
SendResponse(false, mobile_apis::Result::IGNORED);
return;
}
- SendUnsubscribeButtonNotification();
- SendResponse(true, mobile_apis::Result::SUCCESS);
+ (*message_)[str::msg_params][str::app_id] = app->app_id();
+ StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons);
+ SendHMIRequest(hmi_apis::FunctionID::Buttons_UnsubscribeButton,
+ &(*message_)[app_mngr::strings::msg_params],
+ true);
+}
+
+void UnsubscribeButtonRequest::on_event(const event_engine::Event& event) {
+ SDL_LOG_AUTO_TRACE();
+ using namespace helpers;
+
+ const smart_objects::SmartObject& message = event.smart_object();
+
+ if (hmi_apis::FunctionID::Buttons_UnsubscribeButton != event.id()) {
+ SDL_LOG_ERROR("Received unknown event.");
+ return;
+ }
+ EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Buttons);
+ ApplicationSharedPtr app =
+ application_manager_.application(CommandRequestImpl::connection_key());
+
+ if (!app) {
+ SDL_LOG_ERROR("NULL pointer.");
+ return;
+ }
+
+ hmi_apis::Common_Result::eType hmi_result =
+ static_cast<hmi_apis::Common_Result::eType>(
+ message[strings::params][hmi_response::code].asInt());
+ std::string response_info;
+ GetInfo(message, response_info);
+ const bool result = PrepareResultForMobileResponse(
+ hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons);
+
+ mobile_apis::Result::eType result_code =
+ MessageHelper::HMIToMobileResult(hmi_result);
+
+ SendResponse(result,
+ result_code,
+ response_info.empty() ? nullptr : response_info.c_str(),
+ &(message[strings::msg_params]));
}
bool UnsubscribeButtonRequest::Init() {
@@ -109,19 +154,6 @@ bool UnsubscribeButtonRequest::Init() {
return true;
}
-void UnsubscribeButtonRequest::SendUnsubscribeButtonNotification() {
- using namespace smart_objects;
- using namespace hmi_apis;
-
- // send OnButtonSubscription notification
- SmartObject msg_params = SmartObject(SmartType_Map);
- msg_params[strings::app_id] = connection_key();
- msg_params[strings::name] = static_cast<Common_ButtonName::eType>(
- (*message_)[strings::msg_params][strings::button_name].asInt());
- msg_params[strings::is_suscribed] = false;
- CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params);
-}
-
} // namespace commands
} // namespace sdl_rpc_plugin
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
index 954ddb4e57..c66e0b6950 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
@@ -77,6 +77,8 @@
#include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h"
#include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_request.h"
#include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_response.h"
+#include "sdl_rpc_plugin/commands/hmi/subscribe_button_request.h"
+#include "sdl_rpc_plugin/commands/hmi/subscribe_button_response.h"
#include "sdl_rpc_plugin/commands/hmi/tts_change_registration_request.h"
#include "sdl_rpc_plugin/commands/hmi/tts_change_registration_response.h"
#include "sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h"
@@ -137,6 +139,8 @@
#include "sdl_rpc_plugin/commands/hmi/ui_slider_response.h"
#include "sdl_rpc_plugin/commands/hmi/ui_subtle_alert_request.h"
#include "sdl_rpc_plugin/commands/hmi/ui_subtle_alert_response.h"
+#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_request.h"
+#include "sdl_rpc_plugin/commands/hmi/unsubscribe_button_response.h"
#include "sdl_rpc_plugin/commands/hmi/update_app_list_request.h"
#include "sdl_rpc_plugin/commands/hmi/update_app_list_response.h"
#include "sdl_rpc_plugin/commands/hmi/update_device_list_request.h"
@@ -207,7 +211,6 @@
#include "sdl_rpc_plugin/commands/hmi/on_app_unregistered_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_button_event_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_button_press_notification.h"
-#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_device_chosen_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_device_state_changed_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_driver_distraction_notification.h"
@@ -680,6 +683,19 @@ CommandCreator& HMICommandFactory::get_creator_factory(
: factory
.GetCreator<commands::ButtonGetCapabilitiesResponse>();
}
+ case hmi_apis::FunctionID::Buttons_SubscribeButton: {
+ return hmi_apis::messageType::request == message_type
+ ? factory.GetCreator<commands::hmi::SubscribeButtonRequest>()
+ : factory.GetCreator<commands::hmi::SubscribeButtonResponse>();
+ }
+
+ case hmi_apis::FunctionID::Buttons_UnsubscribeButton: {
+ return hmi_apis::messageType::request == message_type
+ ? factory.GetCreator<commands::hmi::UnsubscribeButtonRequest>()
+ : factory
+ .GetCreator<commands::hmi::UnsubscribeButtonResponse>();
+ }
+
case hmi_apis::FunctionID::SDL_OnAllowSDLFunctionality: {
return factory
.GetCreator<commands::OnAllowSDLFunctionalityNotification>();
@@ -761,10 +777,6 @@ CommandCreator& HMICommandFactory::get_creator_factory(
case hmi_apis::FunctionID::Buttons_OnButtonPress: {
return factory.GetCreator<commands::hmi::OnButtonPressNotification>();
}
- case hmi_apis::FunctionID::Buttons_OnButtonSubscription: {
- return factory
- .GetCreator<commands::hmi::OnButtonSubscriptionNotification>();
- }
case hmi_apis::FunctionID::Navigation_OnTBTClientState: {
return factory.GetCreator<commands::OnNaviTBTClientStateNotification>();
}
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc
index 5e485adb7f..2a0eda2b10 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc
@@ -97,7 +97,6 @@
#include "hmi/on_audio_data_streaming_notification.h"
#include "hmi/on_button_event_notification.h"
#include "hmi/on_button_press_notification.h"
-#include "hmi/on_button_subscription_notification.h"
#include "hmi/on_device_chosen_notification.h"
#include "hmi/on_device_state_changed_notification.h"
#include "hmi/on_driver_distraction_notification.h"
@@ -148,6 +147,8 @@
#include "hmi/sdl_get_user_friendly_message_response.h"
#include "hmi/sdl_policy_update.h"
#include "hmi/sdl_policy_update_response.h"
+#include "hmi/subscribe_button_request.h"
+#include "hmi/subscribe_button_response.h"
#include "hmi/tts_change_registration_request.h"
#include "hmi/tts_change_registration_response.h"
#include "hmi/tts_get_capabilities_request.h"
@@ -206,6 +207,8 @@
#include "hmi/ui_slider_response.h"
#include "hmi/ui_subtle_alert_request.h"
#include "hmi/ui_subtle_alert_response.h"
+#include "hmi/unsubscribe_button_request.h"
+#include "hmi/unsubscribe_button_response.h"
#include "hmi/update_app_list_request.h"
#include "hmi/update_app_list_response.h"
#include "hmi/update_device_list_request.h"
@@ -445,7 +448,6 @@ typedef Types<commands::NaviIsReadyResponse,
typedef Types<commands::hmi::OnButtonEventNotification,
commands::hmi::OnButtonPressNotification,
- commands::hmi::OnButtonSubscriptionNotification,
commands::OnNaviTBTClientStateNotification,
commands::hmi::OnUIKeyBoardInputNotification,
commands::hmi::OnUITouchEventNotification,
@@ -495,8 +497,12 @@ typedef Types<commands::AllowAllAppsRequest,
commands::AllowAppResponse,
commands::BCGetFilePathRequest,
commands::BCGetFilePathResponse,
+ commands::hmi::SubscribeButtonRequest,
+ commands::hmi::SubscribeButtonResponse,
commands::UISubtleAlertResponse,
- commands::UISubtleAlertRequest>
+ commands::UISubtleAlertRequest,
+ commands::hmi::UnsubscribeButtonRequest,
+ commands::hmi::UnsubscribeButtonResponse>
HMICommandsListFifth;
TYPED_TEST_CASE(HMICommandsTestFirst, HMICommandsListFirst);
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
index bb5008654a..82a5b536a8 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc
@@ -45,7 +45,6 @@
#include "sdl_rpc_plugin/commands/hmi/on_audio_data_streaming_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_button_event_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_button_press_notification.h"
-#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_device_chosen_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_device_state_changed_notification.h"
#include "sdl_rpc_plugin/commands/hmi/on_driver_distraction_notification.h"
@@ -338,7 +337,6 @@ class HMIOnNotificationsEventDispatcher
typedef Types<OnAppPermissionChangedNotification,
OnAudioDataStreamingNotification,
- hmi::OnButtonSubscriptionNotification,
OnFileRemovedNotification,
OnPutFileNotification,
OnResumeAudioSourceNotification,
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_request_test.cc
new file mode 100644
index 0000000000..d339a4acf8
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_request_test.cc
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "hmi/subscribe_button_request.h"
+#include <memory>
+#include <string>
+#include "application_manager/mock_event_dispatcher.h"
+
+#include "gtest/gtest.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace hmi_commands_test {
+namespace subscribe_button_request {
+
+using ::testing::_;
+using ::testing::Return;
+namespace am = ::application_manager;
+namespace strings = am::strings;
+using am::commands::RequestToHMI;
+using am::event_engine::Event;
+using sdl_rpc_plugin::commands::hmi::SubscribeButtonRequest;
+using ::test::components::application_manager_test::MockApplication;
+using ::test::components::event_engine_test::MockEventDispatcher;
+
+typedef std::shared_ptr<MockApplication> MockAppPtr;
+typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr;
+typedef std::shared_ptr<SubscribeButtonRequest> SubscribeButtonRequestPtr;
+
+namespace {
+const uint32_t kCorrelationId = 2u;
+const uint32_t kAppId = 1u;
+const hmi_apis::Common_ButtonName::eType kCustomButtonName =
+ hmi_apis::Common_ButtonName::CUSTOM_BUTTON;
+const hmi_apis::Common_ButtonName::eType kHmiButtonName =
+ hmi_apis::Common_ButtonName::SEEKLEFT;
+const mobile_apis::ButtonName::eType kMobileButtonName =
+ mobile_apis::ButtonName::SEEKLEFT;
+const mobile_apis::ButtonName::eType kMobileCustomButtonName =
+ mobile_apis::ButtonName::CUSTOM_BUTTON;
+const hmi_apis::FunctionID::eType kFunctionID =
+ hmi_apis::FunctionID::Buttons_SubscribeButton;
+} // namespace
+
+class HMISubscribeButtonRequestTest
+ : public CommandRequestTest<CommandsTestMocks::kIsNice> {
+ protected:
+ MessageSharedPtr CreateCommandMsg() {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[strings::msg_params][strings::app_id] = kAppId;
+ (*command_msg)[strings::msg_params][strings::button_name] = kHmiButtonName;
+ (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId;
+ (*command_msg)[strings::params][strings::function_id] = kFunctionID;
+
+ return command_msg;
+ }
+
+ void InitCommand(const uint32_t& timeout) OVERRIDE {
+ mock_app_ = CreateMockApp();
+ CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout);
+ ON_CALL((*mock_app_), hmi_app_id()).WillByDefault(Return(kAppId));
+ ON_CALL(app_mngr_, application_by_hmi_app(kAppId))
+ .WillByDefault(Return(mock_app_));
+ ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_));
+ }
+
+ MockAppPtr mock_app_;
+};
+
+TEST_F(HMISubscribeButtonRequestTest, Run_SendRequest_SUCCESS) {
+ MockEventDispatcher mock_event_dispatcher;
+ EXPECT_CALL(app_mngr_, event_dispatcher())
+ .WillOnce(ReturnRef(mock_event_dispatcher));
+
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ RequestToHMIPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
+
+ EXPECT_CALL(mock_event_dispatcher,
+ add_observer(kFunctionID, kCorrelationId, _))
+ .Times(0);
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg));
+ ASSERT_TRUE(command->Init());
+
+ command->Run();
+}
+
+TEST_F(HMISubscribeButtonRequestTest, Run_SendRequest_CUSTOM_BUTTON_SUCCESS) {
+ MockEventDispatcher mock_event_dispatcher;
+ EXPECT_CALL(app_mngr_, event_dispatcher())
+ .WillOnce(ReturnRef(mock_event_dispatcher));
+
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName;
+ RequestToHMIPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
+
+ EXPECT_CALL(mock_event_dispatcher,
+ add_observer(kFunctionID, kCorrelationId, _));
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg));
+
+ ASSERT_TRUE(command->Init());
+ command->Run();
+}
+
+TEST_F(HMISubscribeButtonRequestTest,
+ onTimeOut_RequestIsExpired_HandleOnTimeout) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ RequestToHMIPtr command(CreateCommand<SubscribeButtonRequest>(command_msg));
+
+ resumption_test::MockResumeCtrl mock_resume_ctrl;
+ ON_CALL(app_mngr_, resume_controller())
+ .WillByDefault(ReturnRef(mock_resume_ctrl));
+ EXPECT_CALL(mock_resume_ctrl, HandleOnTimeOut(kCorrelationId, kFunctionID));
+
+ command->onTimeOut();
+}
+
+TEST_F(HMISubscribeButtonRequestTest,
+ OnEvent_SuccessfulResponse_ButtonSubscribed) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName;
+
+ SubscribeButtonRequestPtr command =
+ CreateCommand<SubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileCustomButtonName))
+ .WillOnce(Return(true));
+
+ command->on_event(event);
+}
+
+TEST_F(HMISubscribeButtonRequestTest,
+ OnEvent_UnsuccessfulResponse_ButtonNotSubscribed) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ (*command_msg)[strings::msg_params][strings::button_name] = kCustomButtonName;
+
+ SubscribeButtonRequestPtr command =
+ CreateCommand<SubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::GENERIC_ERROR;
+
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileCustomButtonName)).Times(0);
+
+ command->on_event(event);
+}
+
+TEST_F(HMISubscribeButtonRequestTest, onEvent_App_NULL) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ SubscribeButtonRequestPtr command =
+ CreateCommand<SubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ MockAppPtr mock_app = NULL;
+ EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppId))
+ .WillOnce(Return(mock_app));
+
+ EXPECT_CALL(*mock_app_, SubscribeToButton(kMobileButtonName)).Times(0);
+
+ command->on_event(event);
+}
+
+} // namespace subscribe_button_request
+} // namespace hmi_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc
new file mode 100644
index 0000000000..ca4c2ee41b
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/subscribe_button_response_test.cc
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string>
+
+#include "application_manager/mock_event_dispatcher.h"
+#include "gtest/gtest.h"
+#include "hmi/subscribe_button_response.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace hmi_commands_test {
+namespace subscribe_button_response {
+
+namespace am = ::application_manager;
+using application_manager::ExpiredButtonRequestData;
+using application_manager::commands::ResponseFromHMI;
+using sdl_rpc_plugin::commands::hmi::SubscribeButtonResponse;
+using ::test::components::event_engine_test::MockEventDispatcher;
+typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr;
+
+namespace {
+const uint32_t kCorrelationId = 2u;
+const uint32_t kAppId = 1u;
+const hmi_apis::Common_ButtonName::eType kButtonName =
+ hmi_apis::Common_ButtonName::SEEKLEFT;
+const hmi_apis::FunctionID::eType kFunctionID =
+ hmi_apis::FunctionID::Buttons_UnsubscribeButton;
+} // namespace
+
+class HMISubscribeButtonResponseTest
+ : public CommandsTest<CommandsTestMocks::kIsNice> {
+ public:
+ HMISubscribeButtonResponseTest() {
+ ON_CALL(app_mngr_, event_dispatcher())
+ .WillByDefault(ReturnRef(event_dispatcher_));
+ }
+
+ MessageSharedPtr CreateCommandMsg() {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId;
+ (*command_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+
+ return command_msg;
+ }
+
+ MockEventDispatcher event_dispatcher_;
+};
+
+TEST_F(HMISubscribeButtonResponseTest,
+ RUN_ProcessExpiredRequest_SendUnsubscribeRequestToHMI) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ ResponseFromHMIPtr command(
+ CreateCommand<SubscribeButtonResponse>(command_msg));
+
+ ExpiredButtonRequestData expired_data;
+ expired_data.app_id_ = kAppId;
+ expired_data.button_name_ = kButtonName;
+ utils::Optional<ExpiredButtonRequestData> expired_data_opt = expired_data;
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(expired_data_opt));
+ ON_CALL(mock_message_helper_,
+ CreateButtonSubscriptionHandlingRequestToHmi(
+ kAppId, kButtonName, kFunctionID, _))
+ .WillByDefault(Return(command_msg));
+ EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0);
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg));
+
+ command->Run();
+}
+
+TEST_F(
+ HMISubscribeButtonResponseTest,
+ RUN_ProcessUnsuccessfulExpiredRequest_EventNotRaisedUnsubscribeRequestNotSent) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ (*command_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::GENERIC_ERROR;
+
+ ResponseFromHMIPtr command(
+ CreateCommand<SubscribeButtonResponse>(command_msg));
+
+ ExpiredButtonRequestData expired_data;
+ expired_data.app_id_ = kAppId;
+ expired_data.button_name_ = kButtonName;
+ utils::Optional<ExpiredButtonRequestData> expired_data_opt = expired_data;
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(expired_data_opt));
+ EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0);
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0);
+
+ command->Run();
+}
+
+TEST_F(HMISubscribeButtonResponseTest, RUN_NoExpiredRequests_EventRaised) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ ResponseFromHMIPtr command(
+ CreateCommand<SubscribeButtonResponse>(command_msg));
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(utils::Optional<ExpiredButtonRequestData>::EMPTY));
+
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0);
+ EXPECT_CALL(event_dispatcher_, raise_event(_));
+
+ command->Run();
+}
+
+} // namespace subscribe_button_response
+} // namespace hmi_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc
new file mode 100644
index 0000000000..3236987d14
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_request_test.cc
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "hmi/unsubscribe_button_request.h"
+
+#include <memory>
+#include <string>
+
+#include "application_manager/mock_event_dispatcher.h"
+#include "gtest/gtest.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace hmi_commands_test {
+namespace unsubscribe_button_request {
+
+using ::testing::_;
+using ::testing::Return;
+namespace am = ::application_manager;
+namespace strings = am::strings;
+using am::commands::RequestToHMI;
+using am::event_engine::Event;
+using sdl_rpc_plugin::commands::hmi::UnsubscribeButtonRequest;
+using ::test::components::application_manager_test::MockApplication;
+
+typedef std::shared_ptr<MockApplication> MockAppPtr;
+typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr;
+typedef std::shared_ptr<UnsubscribeButtonRequest> UnsubscribeButtonRequestPtr;
+
+namespace {
+const uint32_t kCorrelationId = 2u;
+const uint32_t kAppId = 1u;
+const hmi_apis::Common_ButtonName::eType kButtonName =
+ hmi_apis::Common_ButtonName::CUSTOM_BUTTON;
+const hmi_apis::FunctionID::eType kFunctionID =
+ hmi_apis::FunctionID::Buttons_UnsubscribeButton;
+const mobile_apis::ButtonName::eType kMobileCustomButtonName =
+ mobile_apis::ButtonName::CUSTOM_BUTTON;
+} // namespace
+
+class HMIUnsubscribeButtonRequestTest
+ : public CommandRequestTest<CommandsTestMocks::kIsNice> {
+ protected:
+ MessageSharedPtr CreateCommandMsg() {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[strings::msg_params][strings::app_id] = kAppId;
+ (*command_msg)[strings::msg_params][strings::button_name] = kButtonName;
+ (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId;
+ (*command_msg)[strings::params][strings::function_id] = kFunctionID;
+
+ return command_msg;
+ }
+
+ void InitCommand(const uint32_t& timeout) OVERRIDE {
+ mock_app_ = CreateMockApp();
+ CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout);
+ ON_CALL((*mock_app_), hmi_app_id()).WillByDefault(Return(kAppId));
+ ON_CALL(app_mngr_, application_by_hmi_app(kAppId))
+ .WillByDefault(Return(mock_app_));
+ ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_));
+ }
+
+ MockAppPtr mock_app_;
+};
+
+TEST_F(HMIUnsubscribeButtonRequestTest, Run_SendRequest_SUCCESS) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ RequestToHMIPtr command(CreateCommand<UnsubscribeButtonRequest>(command_msg));
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg));
+ ASSERT_TRUE(command->Init());
+
+ command->Run();
+}
+
+TEST_F(HMIUnsubscribeButtonRequestTest,
+ onTimeOut_RequestIsExpired_HandleOnTimeout) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ RequestToHMIPtr command(CreateCommand<UnsubscribeButtonRequest>(command_msg));
+
+ resumption_test::MockResumeCtrl mock_resume_ctrl;
+ ON_CALL(app_mngr_, resume_controller())
+ .WillByDefault(ReturnRef(mock_resume_ctrl));
+ EXPECT_CALL(mock_resume_ctrl, HandleOnTimeOut(_, _));
+
+ command->onTimeOut();
+}
+
+TEST_F(HMIUnsubscribeButtonRequestTest,
+ OnEvent_SuccessfulResponse_ButtonUnsubscribed) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ UnsubscribeButtonRequestPtr command =
+ CreateCommand<UnsubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName))
+ .WillOnce(Return(true));
+
+ command->on_event(event);
+}
+
+TEST_F(HMIUnsubscribeButtonRequestTest,
+ OnEvent_UnsuccessfulResponse_ButtonNotUnsubscribed) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ UnsubscribeButtonRequestPtr command =
+ CreateCommand<UnsubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::GENERIC_ERROR;
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName))
+ .Times(0);
+
+ command->on_event(event);
+}
+
+TEST_F(HMIUnsubscribeButtonRequestTest, onEvent_App_NULL) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ UnsubscribeButtonRequestPtr command =
+ CreateCommand<UnsubscribeButtonRequest>(command_msg);
+
+ MessageSharedPtr event_msg = CreateCommandMsg();
+ (*event_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+
+ Event event(kFunctionID);
+ event.set_smart_object(*event_msg);
+
+ MockAppPtr mock_app = NULL;
+ EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppId))
+ .WillOnce(Return(mock_app));
+
+ EXPECT_CALL(*mock_app_, UnsubscribeFromButton(kMobileCustomButtonName))
+ .Times(0);
+
+ command->on_event(event);
+}
+
+} // namespace unsubscribe_button_request
+} // namespace hmi_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc
new file mode 100644
index 0000000000..3d9572a743
--- /dev/null
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/unsubscribe_button_response_test.cc
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string>
+
+#include "application_manager/mock_event_dispatcher.h"
+#include "gtest/gtest.h"
+#include "hmi/unsubscribe_button_response.h"
+
+namespace test {
+namespace components {
+namespace commands_test {
+namespace hmi_commands_test {
+namespace unsubscribe_button_response {
+
+namespace am = ::application_manager;
+using application_manager::ExpiredButtonRequestData;
+using application_manager::commands::ResponseFromHMI;
+using sdl_rpc_plugin::commands::hmi::UnsubscribeButtonResponse;
+using ::test::components::event_engine_test::MockEventDispatcher;
+typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr;
+
+namespace {
+const uint32_t kCorrelationId = 2u;
+const uint32_t kAppId = 1u;
+const hmi_apis::Common_ButtonName::eType kButtonName =
+ hmi_apis::Common_ButtonName::SEEKLEFT;
+const hmi_apis::FunctionID::eType kFunctionID =
+ hmi_apis::FunctionID::Buttons_SubscribeButton;
+} // namespace
+
+class HMIUnsubscribeButtonResponseTest
+ : public CommandsTest<CommandsTestMocks::kIsNice> {
+ public:
+ HMIUnsubscribeButtonResponseTest() {
+ ON_CALL(app_mngr_, event_dispatcher())
+ .WillByDefault(ReturnRef(event_dispatcher_));
+ }
+
+ MessageSharedPtr CreateCommandMsg() {
+ MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map));
+ (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId;
+ (*command_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::SUCCESS;
+
+ return command_msg;
+ }
+
+ MockEventDispatcher event_dispatcher_;
+};
+
+TEST_F(HMIUnsubscribeButtonResponseTest,
+ RUN_ProcessExpiredRequest_SendSubscribeRequestToHMI) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+
+ ResponseFromHMIPtr command(
+ CreateCommand<UnsubscribeButtonResponse>(command_msg));
+
+ ExpiredButtonRequestData expired_data;
+ expired_data.app_id_ = kAppId;
+ expired_data.button_name_ = kButtonName;
+ utils::Optional<ExpiredButtonRequestData> expired_data_opt = expired_data;
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(expired_data_opt));
+ ON_CALL(mock_message_helper_,
+ CreateButtonSubscriptionHandlingRequestToHmi(
+ kAppId, kButtonName, kFunctionID, _))
+ .WillByDefault(Return(command_msg));
+ EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0);
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg));
+
+ command->Run();
+}
+
+TEST_F(
+ HMIUnsubscribeButtonResponseTest,
+ RUN_ProcessUnsuccessfulExpiredRequest_EventNotRaisedSubscribeRequestNotSent) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ (*command_msg)[am::strings::params][am::hmi_response::code] =
+ hmi_apis::Common_Result::GENERIC_ERROR;
+
+ ResponseFromHMIPtr command(
+ CreateCommand<UnsubscribeButtonResponse>(command_msg));
+
+ ExpiredButtonRequestData expired_data;
+ expired_data.app_id_ = kAppId;
+ expired_data.button_name_ = kButtonName;
+ utils::Optional<ExpiredButtonRequestData> expired_data_opt = expired_data;
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(expired_data_opt));
+ EXPECT_CALL(event_dispatcher_, raise_event(_)).Times(0);
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0);
+
+ command->Run();
+}
+
+TEST_F(HMIUnsubscribeButtonResponseTest, RUN_NoExpiredRequests_EventRaised) {
+ MessageSharedPtr command_msg = CreateCommandMsg();
+ ResponseFromHMIPtr command(
+ CreateCommand<UnsubscribeButtonResponse>(command_msg));
+
+ ON_CALL(app_mngr_, GetExpiredButtonRequestData(kCorrelationId))
+ .WillByDefault(Return(utils::Optional<ExpiredButtonRequestData>::EMPTY));
+
+ EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0);
+ EXPECT_CALL(event_dispatcher_, raise_event(_));
+ command->Run();
+}
+
+} // namespace unsubscribe_button_response
+} // namespace hmi_commands_test
+} // namespace commands_test
+} // namespace components
+} // namespace test
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc
index e4536ddeea..dbab9e1833 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc
@@ -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));
@@ -215,6 +218,13 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) {
(*notification_msg)[am::strings::msg_params]
[am::hmi_response::custom_button_id] = kCustomButtonId;
+ auto mock_message_helper = am::MockMessageHelper::message_helper_mock();
+ smart_objects::SmartObjectSPtr msg =
+ std::make_shared<smart_objects::SmartObject>();
+ (*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId;
+ EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _))
+ .WillRepeatedly(Return(msg));
+
std::shared_ptr<Notification> command(
this->template CreateCommand<Notification>(notification_msg));
@@ -222,6 +232,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_,
@@ -244,18 +257,30 @@ TYPED_TEST(OnButtonNotificationCommandsTest,
(*notification_msg)[am::strings::msg_params]
[am::hmi_response::custom_button_id] = kCustomButtonId;
+ 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));
+
std::shared_ptr<Notification> command(
this->template CreateCommand<Notification>(notification_msg));
typename TestFixture::MockAppPtr mock_app = this->CreateMockApp();
- ON_CALL(*mock_app, hmi_level(kDefaultWindowId))
- .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND));
+
+ EXPECT_CALL(*mock_app, GetSoftButtonWindowID(kCustomButtonId))
+ .WillOnce(Return(kDefaultWindowId));
+
+ EXPECT_CALL(*mock_app, hmi_level(kDefaultWindowId))
+ .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));
- EXPECT_CALL(this->mock_rpc_service_,
- SendMessageToMobile(
- CheckNotificationMessage(TestFixture::kFunctionId), _));
command->Run();
}
@@ -343,22 +368,27 @@ 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>();
+ (*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId;
+ 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), _));
+ EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app));
command->Run();
}
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc
index 99491873be..5d940c4f4c 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc
@@ -289,8 +289,7 @@ class RegisterAppInterfaceRequestTest
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _))
+ HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.Times(0);
EXPECT_CALL(
@@ -350,12 +349,6 @@ class RegisterAppInterfaceRequestTest
hmi_apis::FunctionID::BasicCommunication_OnAppRegistered),
_))
.WillByDefault(Return(true));
- ON_CALL(
- mock_rpc_service_,
- ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _))
- .WillByDefault(Return(true));
}
void SetCommonPreconditionsToCheckWithPolicyData(MockAppPtr mock_app) {
@@ -456,11 +449,22 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) {
hmi_apis::FunctionID::BasicCommunication_OnAppRegistered),
_))
.WillOnce(Return(true));
+
+ ON_CALL(mock_hmi_interfaces_,
+ GetInterfaceState(
+ application_manager::HmiInterfaces::HMI_INTERFACE_Buttons))
+ .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE));
+
+ ON_CALL(
+ mock_hmi_interfaces_,
+ GetInterfaceFromFunction(hmi_apis::FunctionID::Buttons_SubscribeButton))
+ .WillByDefault(
+ Return(application_manager::HmiInterfaces::HMI_INTERFACE_Buttons));
+
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _))
+ HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.WillOnce(Return(true));
application_manager::DisplayCapabilitiesBuilder builder(*mock_app);
@@ -583,8 +587,7 @@ TEST_F(RegisterAppInterfaceRequestTest,
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _))
+ HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
@@ -848,8 +851,7 @@ TEST_F(RegisterAppInterfaceRequestTest,
EXPECT_CALL(
mock_rpc_service_,
ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _))
+ HMIResultCodeIs(hmi_apis::FunctionID::Buttons_SubscribeButton), _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_rpc_service_,
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc
index f3bfe12ab1..56e0766184 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc
@@ -202,22 +202,19 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) {
EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _))
.WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true)));
- MessageSharedPtr mobile_result_msg;
- EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _))
- .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true)));
ASSERT_TRUE(command->Init());
command->Run();
- EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription,
+ EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton,
static_cast<hmi_apis::FunctionID::eType>(
(*hmi_result_msg)[am::strings::params][am::strings::function_id]
.asInt()));
- EXPECT_EQ(mobile_apis::Result::SUCCESS,
- static_cast<mobile_apis::Result::eType>(
- (*mobile_result_msg)[am::strings::msg_params]
- [am::strings::result_code]
- .asInt()));
+ EXPECT_EQ(
+ hmi_apis::Common_ButtonName::eType::SEEKLEFT,
+ static_cast<hmi_apis::Common_ButtonName::eType>(
+ (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name]
+ .asInt()));
}
TEST_F(SubscribeButtonRequestTest, Run_NAV_SUCCESS) {
@@ -249,30 +246,30 @@ TEST_F(SubscribeButtonRequestTest, Run_NAV_SUCCESS) {
EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _))
.WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true)));
- MessageSharedPtr mobile_result_msg;
- EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _))
- .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true)));
ASSERT_TRUE(command->Init());
command->Run();
- EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription,
+ EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton,
static_cast<hmi_apis::FunctionID::eType>(
(*hmi_result_msg)[am::strings::params][am::strings::function_id]
.asInt()));
- EXPECT_EQ(mobile_apis::Result::SUCCESS,
- static_cast<mobile_apis::Result::eType>(
- (*mobile_result_msg)[am::strings::msg_params]
- [am::strings::result_code]
- .asInt()));
+ EXPECT_EQ(
+ hmi_apis::Common_ButtonName::eType::NAV_CENTER_LOCATION,
+ static_cast<hmi_apis::Common_ButtonName::eType>(
+ (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name]
+ .asInt()));
}
-TEST_F(SubscribeButtonRequestTest, Run_SUCCESS_App_Base_RPC_Version) {
- const mobile_apis::ButtonName::eType kButtonName =
- mobile_apis::ButtonName::OK;
+TEST_F(SubscribeButtonRequestTest,
+ Run_App_Version_4_5_and_OK_btn_Expect_PlayPause_btn_sent_to_HMI) {
+ const mobile_apis::ButtonName::eType button_ok = mobile_apis::ButtonName::OK;
- MessageSharedPtr msg(CreateMessage());
- (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName;
+ const mobile_apis::ButtonName::eType button_play_pause =
+ mobile_apis::ButtonName::PLAY_PAUSE;
+
+ MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map));
+ (*msg)[am::strings::msg_params][am::strings::button_name] = button_ok;
CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg));
MockAppPtr app(CreateMockApp());
@@ -284,41 +281,33 @@ TEST_F(SubscribeButtonRequestTest, Run_SUCCESS_App_Base_RPC_Version) {
.WillByDefault(Return(true));
MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map));
- (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName;
- (*button_caps_ptr)[1][am::hmi_response::button_name] =
- mobile_apis::ButtonName::PLAY_PAUSE;
+ (*button_caps_ptr)[0][am::hmi_response::button_name] = button_ok;
+ (*button_caps_ptr)[1][am::hmi_response::button_name] = button_play_pause;
ON_CALL(mock_hmi_capabilities_, button_capabilities())
.WillByDefault(Return(button_caps_ptr));
- ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false));
+ ON_CALL(*app, IsSubscribedToButton(button_play_pause))
+ .WillByDefault(Return(false));
MessageSharedPtr hmi_result_msg;
EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _))
.WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true)));
- MessageSharedPtr mobile_result_msg;
- EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _))
- .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true)));
ASSERT_TRUE(command->Init());
command->Run();
- EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription,
+ EXPECT_EQ(hmi_apis::FunctionID::Buttons_SubscribeButton,
static_cast<hmi_apis::FunctionID::eType>(
(*hmi_result_msg)[am::strings::params][am::strings::function_id]
.asInt()));
- EXPECT_EQ(hmi_apis::Common_ButtonName::PLAY_PAUSE,
- static_cast<hmi_apis::Common_ButtonName::eType>(
- (*hmi_result_msg)[am::strings::msg_params][am::strings::name]
- .asInt()));
-
- EXPECT_EQ(mobile_apis::Result::SUCCESS,
- static_cast<mobile_apis::Result::eType>(
- (*mobile_result_msg)[am::strings::msg_params]
- [am::strings::result_code]
- .asInt()));
+ EXPECT_EQ(
+ hmi_apis::Common_ButtonName::PLAY_PAUSE,
+ static_cast<hmi_apis::Common_ButtonName::eType>(
+ (*hmi_result_msg)[am::strings::msg_params][am::strings::button_name]
+ .asInt()));
}
} // namespace subscribe_button_request
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc
index 5735610051..15795fa1e6 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc
@@ -77,8 +77,6 @@ TEST_F(UnsubscribeButtonRequestTest,
.WillOnce(Return(mock_app));
ON_CALL(*mock_app, msg_version())
.WillByDefault(ReturnRef(mock_semantic_version));
- EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId))
- .WillOnce(Return(false));
EXPECT_CALL(
mock_rpc_service_,
@@ -137,18 +135,6 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) {
ON_CALL(*mock_app, msg_version())
.WillByDefault(ReturnRef(mock_semantic_version));
- EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId))
- .WillOnce(Return(true));
- EXPECT_CALL(
- mock_rpc_service_,
- ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _));
- EXPECT_CALL(
- mock_rpc_service_,
- ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _));
-
- EXPECT_CALL(*mock_app, UpdateHash());
command->Init();
command->Run();
}
@@ -181,19 +167,6 @@ TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS_Base_RPC_Version) {
.WillByDefault(ReturnRef(mock_base_rpc_version));
ON_CALL(*mock_app, is_media_application()).WillByDefault(Return(true));
- EXPECT_CALL(*mock_app,
- UnsubscribeFromButton(mobile_apis::ButtonName::PLAY_PAUSE))
- .WillOnce(Return(true));
- EXPECT_CALL(
- mock_rpc_service_,
- ManageHMICommand(
- HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription),
- _));
- EXPECT_CALL(
- mock_rpc_service_,
- ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _));
-
- EXPECT_CALL(*mock_app, UpdateHash());
command->Init();
command->Run();
}
diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc
index 2952fd5481..a53141b5be 100644
--- a/src/components/application_manager/src/application_impl.cc
+++ b/src/components/application_manager/src/application_impl.cc
@@ -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();
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc
index e78d6ee668..c3f3ef4bb3 100644
--- a/src/components/application_manager/src/application_manager_impl.cc
+++ b/src/components/application_manager/src/application_manager_impl.cc
@@ -3182,6 +3182,11 @@ void ApplicationManagerImpl::UnregisterAllApplications() {
resume_controller().OnIgnitionOff();
}
request_ctrl_->TerminateAllHMIRequests();
+
+ {
+ sync_primitives::AutoLock lock(expired_button_requests_lock_);
+ expired_button_requests_.clear();
+ }
}
void ApplicationManagerImpl::RemoveAppsWaitingForRegistration(
@@ -5024,4 +5029,36 @@ void ApplicationManagerImpl::ChangeAppsHMILevel(
}
}
+void ApplicationManagerImpl::AddExpiredButtonRequest(
+ const uint32_t app_id,
+ const int32_t corr_id,
+ const hmi_apis::Common_ButtonName::eType button_name) {
+ SDL_LOG_AUTO_TRACE();
+
+ sync_primitives::AutoLock lock(expired_button_requests_lock_);
+ expired_button_requests_[corr_id] = {app_id, button_name};
+}
+
+utils::Optional<ExpiredButtonRequestData>
+ApplicationManagerImpl::GetExpiredButtonRequestData(
+ const int32_t corr_id) const {
+ SDL_LOG_AUTO_TRACE();
+ sync_primitives::AutoLock lock(expired_button_requests_lock_);
+
+ auto found_subscription = expired_button_requests_.find(corr_id);
+ if (found_subscription == expired_button_requests_.end()) {
+ return utils::Optional<ExpiredButtonRequestData>::EMPTY;
+ }
+
+ return utils::Optional<ExpiredButtonRequestData>(found_subscription->second);
+}
+
+void ApplicationManagerImpl::DeleteExpiredButtonRequest(const int32_t corr_id) {
+ SDL_LOG_AUTO_TRACE();
+
+ sync_primitives::AutoLock lock(expired_button_requests_lock_);
+ auto found_subscription = expired_button_requests_.find(corr_id);
+ expired_button_requests_.erase(found_subscription);
+}
+
} // namespace application_manager
diff --git a/src/components/application_manager/src/commands/button_notification_to_mobile.cc b/src/components/application_manager/src/commands/button_notification_to_mobile.cc
new file mode 100644
index 0000000000..a94f4ef6ab
--- /dev/null
+++ b/src/components/application_manager/src/commands/button_notification_to_mobile.cc
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2021, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "application_manager/commands/button_notification_to_mobile.h"
+#include "interfaces/MOBILE_API.h"
+namespace application_manager {
+
+namespace commands {
+namespace app_mngr = application_manager;
+
+SDL_CREATE_LOG_VARIABLE("ButtonNotificationToMobile")
+
+ButtonNotificationToMobile::ButtonNotificationToMobile(
+ const app_mngr::commands::MessageSharedPtr& message,
+ app_mngr::ApplicationManager& application_manager,
+ app_mngr::rpc_service::RPCService& rpc_service,
+ app_mngr::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handler)
+ : CommandNotificationImpl(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handler) {}
+
+ButtonNotificationToMobile::~ButtonNotificationToMobile() {}
+
+bool ButtonNotificationToMobile::DoesParamExist(
+ const std::string& param_name) const {
+ SDL_LOG_AUTO_TRACE();
+ using namespace application_manager::strings;
+ return (*message_)[msg_params].keyExists(param_name);
+}
+
+void ButtonNotificationToMobile::HandleCustomButton(
+ app_mngr::ApplicationSharedPtr app) {
+ SDL_LOG_AUTO_TRACE();
+ using namespace application_manager::strings;
+
+ if (!app) {
+ SDL_LOG_ERROR("Application doesn't exist.");
+ return;
+ }
+
+ // custom_button_id is mandatory for CUSTOM_BUTTON notification
+ if (!DoesParamExist(hmi_response::custom_button_id)) {
+ SDL_LOG_ERROR(
+ "CUSTOM_BUTTON mobile notification without custom_button_id.");
+ 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();
+
+ if (!app->IsSubscribedToSoftButton(custom_btn_id)) {
+ SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id.");
+ return;
+ }
+
+ const auto window_id = app->GetSoftButtonWindowID(custom_btn_id);
+ (*message_)[strings::msg_params][strings::window_id] = window_id;
+
+ if (mobile_api::HMILevel::HMI_NONE == app->hmi_level(window_id)) {
+ SDL_LOG_WARN("CUSTOM_BUTTON mobile notification is allowed only "
+ << "in FULL, LIMITED or BACKGROUND hmi level");
+ return;
+ }
+
+ SendButtonNotification(app);
+ return;
+}
+
+void ButtonNotificationToMobile::HandleOKButton(
+ app_mngr::ApplicationSharedPtr app) {
+ SDL_LOG_AUTO_TRACE();
+ using namespace application_manager;
+ SDL_LOG_DEBUG("OK button received");
+
+ if (app) {
+ 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(),
+ [](const ApplicationSharedPtr subscribed_app) {
+ return subscribed_app->IsFullscreen();
+ });
+
+ if (app_ptr != subscribed_apps.end()) {
+ SDL_LOG_DEBUG("Sending button press for app in FULL with app id: "
+ << (*app_ptr)->app_id());
+ SendButtonNotification(*app_ptr);
+ } else {
+ SDL_LOG_ERROR("No application found");
+ }
+}
+
+std::vector<ApplicationSharedPtr> ButtonNotificationToMobile::SubscribedApps()
+ const {
+ const uint32_t btn_id = static_cast<uint32_t>(
+ (*message_)[strings::msg_params][hmi_response::button_name].asInt());
+ return application_manager_.applications_by_button(btn_id);
+}
+
+void ButtonNotificationToMobile::HandleMediaButton(
+ app_mngr::ApplicationSharedPtr app) {
+ SDL_LOG_AUTO_TRACE();
+ using namespace application_manager;
+
+ if (app) {
+ 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(),
+ [](const ApplicationSharedPtr subscribed_app) {
+ return helpers::Compare<mobile_api::HMILevel::eType,
+ helpers::EQ,
+ helpers::ONE>(
+ subscribed_app->hmi_level(
+ mobile_apis::PredefinedWindows::DEFAULT_WINDOW),
+ mobile_api::HMILevel::HMI_FULL,
+ mobile_api::HMILevel::HMI_LIMITED);
+ });
+
+ if (app_ptr != subscribed_apps.end()) {
+ SendButtonNotification(*app_ptr);
+ } else {
+ SDL_LOG_ERROR("No application found");
+ }
+}
+
+void ButtonNotificationToMobile::Run() {
+ SDL_LOG_AUTO_TRACE();
+ using namespace application_manager::strings;
+
+ const uint32_t btn_id = static_cast<uint32_t>(
+ (*message_)[msg_params][hmi_response::button_name].asInt());
+
+ SDL_LOG_DEBUG("Received button id: " << btn_id);
+
+ ApplicationSharedPtr app;
+
+ if (DoesParamExist(strings::app_id)) {
+ app = application_manager_.application(
+ (*message_)[msg_params][app_id].asUInt());
+ }
+
+ if (static_cast<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) {
+ HandleCustomButton(app);
+ } else if (static_cast<uint32_t>(mobile_apis::ButtonName::OK) == btn_id) {
+ HandleOKButton(app);
+ } else {
+ HandleMediaButton(app);
+ }
+}
+
+} // namespace commands
+} // namespace application_manager
diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc
index c6ad7b79c1..8751823e85 100644
--- a/src/components/application_manager/src/commands/command_impl.cc
+++ b/src/components/application_manager/src/commands/command_impl.cc
@@ -71,6 +71,30 @@ namespace commands {
SDL_CREATE_LOG_VARIABLE("Commands")
+bool IsMobileResultSuccess(const mobile_apis::Result::eType result_code) {
+ using namespace helpers;
+ return Compare<mobile_apis::Result::eType, EQ, ONE>(
+ result_code,
+ mobile_apis::Result::SUCCESS,
+ mobile_apis::Result::WARNINGS,
+ mobile_apis::Result::WRONG_LANGUAGE,
+ mobile_apis::Result::RETRY,
+ mobile_apis::Result::SAVED,
+ mobile_apis::Result::TRUNCATED_DATA);
+}
+
+bool IsHMIResultSuccess(const hmi_apis::Common_Result::eType result_code) {
+ using namespace helpers;
+ return Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ result_code,
+ hmi_apis::Common_Result::SUCCESS,
+ hmi_apis::Common_Result::WARNINGS,
+ hmi_apis::Common_Result::WRONG_LANGUAGE,
+ hmi_apis::Common_Result::RETRY,
+ hmi_apis::Common_Result::SAVED,
+ hmi_apis::Common_Result::TRUNCATED_DATA);
+}
+
const int32_t CommandImpl::hmi_protocol_type_ = 1;
const int32_t CommandImpl::mobile_protocol_type_ = 0;
const int32_t CommandImpl::protocol_version_ = 3;
@@ -545,5 +569,19 @@ bool CommandImpl::CheckSyntax(const std::string& str,
return true;
}
+bool CommandImpl::IsHMIResultSuccess(
+ hmi_apis::Common_Result::eType result_code,
+ HmiInterfaces::InterfaceID interface) const {
+ SDL_LOG_AUTO_TRACE();
+ if (application_manager::commands::IsHMIResultSuccess(result_code)) {
+ return true;
+ }
+
+ const HmiInterfaces::InterfaceState state =
+ application_manager_.hmi_interfaces().GetInterfaceState(interface);
+ return hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code &&
+ HmiInterfaces::STATE_NOT_AVAILABLE != state;
+}
+
} // namespace commands
} // namespace application_manager
diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc
index 3b0c6bf98c..65fbf7e66f 100644
--- a/src/components/application_manager/src/commands/command_request_impl.cc
+++ b/src/components/application_manager/src/commands/command_request_impl.cc
@@ -161,7 +161,7 @@ ResponseInfo::ResponseInfo(const hmi_apis::Common_Result::eType result,
interface_state =
application_manager.hmi_interfaces().GetInterfaceState(hmi_interface);
- is_ok = CommandRequestImpl::IsHMIResultSuccess(result_code);
+ is_ok = IsHMIResultSuccess(result_code);
is_not_used = hmi_apis::Common_Result::INVALID_ENUM == result_code;
@@ -699,49 +699,11 @@ bool CommandRequestImpl::HasDisallowedParams() const {
(!removed_parameters_permissions_.undefined_params.empty()));
}
-bool CommandRequestImpl::IsMobileResultSuccess(
- const mobile_apis::Result::eType result_code) {
- SDL_LOG_AUTO_TRACE();
- using namespace helpers;
- return Compare<mobile_apis::Result::eType, EQ, ONE>(
- result_code,
- mobile_apis::Result::SUCCESS,
- mobile_apis::Result::WARNINGS,
- mobile_apis::Result::WRONG_LANGUAGE,
- mobile_apis::Result::RETRY,
- mobile_apis::Result::SAVED,
- mobile_apis::Result::TRUNCATED_DATA);
-}
-
-bool CommandRequestImpl::IsHMIResultSuccess(
- const hmi_apis::Common_Result::eType result_code) {
- SDL_LOG_AUTO_TRACE();
- using namespace helpers;
- return Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
- result_code,
- hmi_apis::Common_Result::SUCCESS,
- hmi_apis::Common_Result::WARNINGS,
- hmi_apis::Common_Result::WRONG_LANGUAGE,
- hmi_apis::Common_Result::RETRY,
- hmi_apis::Common_Result::SAVED,
- hmi_apis::Common_Result::TRUNCATED_DATA);
-}
-
bool CommandRequestImpl::PrepareResultForMobileResponse(
hmi_apis::Common_Result::eType result_code,
HmiInterfaces::InterfaceID interface) const {
SDL_LOG_AUTO_TRACE();
- if (IsHMIResultSuccess(result_code)) {
- return true;
- }
-
- const HmiInterfaces::InterfaceState state =
- application_manager_.hmi_interfaces().GetInterfaceState(interface);
- if ((hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code) &&
- (HmiInterfaces::STATE_NOT_AVAILABLE != state)) {
- return true;
- }
- return false;
+ return IsHMIResultSuccess(result_code, interface);
}
bool CommandRequestImpl::PrepareResultForMobileResponse(
diff --git a/src/components/application_manager/src/commands/request_from_hmi.cc b/src/components/application_manager/src/commands/request_from_hmi.cc
index 467001d8db..fca48854e2 100644
--- a/src/components/application_manager/src/commands/request_from_hmi.cc
+++ b/src/components/application_manager/src/commands/request_from_hmi.cc
@@ -143,43 +143,6 @@ void RequestFromHMI::FillCommonParametersOfSO(
(message)[strings::params][strings::correlation_id] = correlation_id;
}
-bool RequestFromHMI::IsMobileResultSuccess(
- mobile_apis::Result::eType result_code) const {
- SDL_LOG_AUTO_TRACE();
- using namespace helpers;
- return Compare<mobile_apis::Result::eType, EQ, ONE>(
- result_code,
- mobile_apis::Result::SUCCESS,
- mobile_apis::Result::WARNINGS,
- mobile_apis::Result::WRONG_LANGUAGE,
- mobile_apis::Result::RETRY,
- mobile_apis::Result::SAVED);
-}
-
-bool RequestFromHMI::IsHMIResultSuccess(
- hmi_apis::Common_Result::eType result_code,
- HmiInterfaces::InterfaceID interface) const {
- SDL_LOG_AUTO_TRACE();
- using namespace helpers;
- if (Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
- result_code,
- hmi_apis::Common_Result::SUCCESS,
- hmi_apis::Common_Result::WARNINGS,
- hmi_apis::Common_Result::WRONG_LANGUAGE,
- hmi_apis::Common_Result::RETRY,
- hmi_apis::Common_Result::SAVED)) {
- return true;
- }
-
- const HmiInterfaces::InterfaceState state =
- application_manager_.hmi_interfaces().GetInterfaceState(interface);
- if ((hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code) &&
- (HmiInterfaces::STATE_NOT_AVAILABLE != state)) {
- return true;
- }
- return false;
-}
-
void RequestFromHMI::SendProviderRequest(
const mobile_apis::FunctionID::eType& mobile_function_id,
const hmi_apis::FunctionID::eType& hmi_function_id,
diff --git a/src/components/application_manager/src/commands/request_to_hmi.cc b/src/components/application_manager/src/commands/request_to_hmi.cc
index 35ac71c8bd..3c411b1605 100644
--- a/src/components/application_manager/src/commands/request_to_hmi.cc
+++ b/src/components/application_manager/src/commands/request_to_hmi.cc
@@ -80,26 +80,6 @@ bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager,
return HmiInterfaces::STATE_NOT_AVAILABLE != state;
}
-bool IsResponseCodeSuccess(
- const smart_objects::SmartObject& response_from_hmi) {
- auto response_code = static_cast<hmi_apis::Common_Result::eType>(
- response_from_hmi[strings::params][hmi_response::code].asInt());
-
- using helpers::Compare;
- using helpers::EQ;
- using helpers::ONE;
-
- const bool is_result_success =
- Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
- response_code,
- hmi_apis::Common_Result::SUCCESS,
- hmi_apis::Common_Result::WARNINGS,
- hmi_apis::Common_Result::WRONG_LANGUAGE,
- hmi_apis::Common_Result::RETRY,
- hmi_apis::Common_Result::SAVED);
- return is_result_success;
-}
-
bool ChangeInterfaceState(ApplicationManager& application_manager,
const smart_objects::SmartObject& response_from_hmi,
HmiInterfaces::InterfaceID interface) {
@@ -113,12 +93,14 @@ bool ChangeInterfaceState(ApplicationManager& application_manager,
return false;
}
- // Process response with result
- if (response_from_hmi[strings::params].keyExists(hmi_response::code) &&
- !IsResponseCodeSuccess(response_from_hmi)) {
- application_manager.hmi_interfaces().SetInterfaceState(
- interface, HmiInterfaces::STATE_NOT_AVAILABLE);
- return false;
+ if (response_from_hmi[strings::params].keyExists(hmi_response::code)) {
+ auto response_code = static_cast<hmi_apis::Common_Result::eType>(
+ response_from_hmi[strings::params][hmi_response::code].asInt());
+ if (!IsHMIResultSuccess(response_code)) {
+ application_manager.hmi_interfaces().SetInterfaceState(
+ interface, HmiInterfaces::STATE_NOT_AVAILABLE);
+ return false;
+ }
}
application_manager.hmi_interfaces().SetInterfaceState(
diff --git a/src/components/application_manager/src/helpers/application_helper.cc b/src/components/application_manager/src/helpers/application_helper.cc
index 863d85a7f0..09b8eed6fe 100644
--- a/src/components/application_manager/src/helpers/application_helper.cc
+++ b/src/components/application_manager/src/helpers/application_helper.cc
@@ -95,13 +95,19 @@ void DeleteGlobalProperties(ApplicationSharedPtr app,
void DeleteButtonSubscriptions(ApplicationSharedPtr app,
ApplicationManager& app_manager) {
ButtonSubscriptions buttons = app->SubscribedButtons().GetData();
-
for (auto button : buttons) {
- if (mobile_apis::ButtonName::CUSTOM_BUTTON == button) {
+ const auto hmi_button =
+ static_cast<hmi_apis::Common_ButtonName::eType>(button);
+ if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == hmi_button) {
continue;
}
- MessageHelper::SendUnsubscribeButtonNotification(button, app, app_manager);
- app->UnsubscribeFromButton(button);
+ smart_objects::SmartObjectSPtr unsubscribe_request =
+ MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ app->app_id(),
+ hmi_button,
+ hmi_apis::FunctionID::Buttons_UnsubscribeButton,
+ app_manager);
+ app_manager.GetRPCService().ManageHMICommand(unsubscribe_request);
}
}
diff --git a/src/components/application_manager/src/hmi_interfaces_impl.cc b/src/components/application_manager/src/hmi_interfaces_impl.cc
index 7365e5e081..205585959b 100644
--- a/src/components/application_manager/src/hmi_interfaces_impl.cc
+++ b/src/components/application_manager/src/hmi_interfaces_impl.cc
@@ -43,8 +43,8 @@ generate_function_to_interface_convert_map() {
convert_map[Buttons_GetCapabilities] = HmiInterfaces::HMI_INTERFACE_Buttons;
convert_map[Buttons_OnButtonEvent] = HmiInterfaces::HMI_INTERFACE_Buttons;
convert_map[Buttons_OnButtonPress] = HmiInterfaces::HMI_INTERFACE_Buttons;
- convert_map[Buttons_OnButtonSubscription] =
- HmiInterfaces::HMI_INTERFACE_Buttons;
+ convert_map[Buttons_SubscribeButton] = HmiInterfaces::HMI_INTERFACE_Buttons;
+ convert_map[Buttons_UnsubscribeButton] = HmiInterfaces::HMI_INTERFACE_Buttons;
convert_map[BasicCommunication_OnReady] =
HmiInterfaces::HMI_INTERFACE_BasicCommunication;
convert_map[BasicCommunication_OnStartDeviceDiscovery] =
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index dde580adeb..decdabb55c 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -819,31 +819,6 @@ void MessageHelper::SendResetPropertiesRequest(ApplicationSharedPtr application,
}
}
-void MessageHelper::SendUnsubscribeButtonNotification(
- mobile_apis::ButtonName::eType button,
- ApplicationSharedPtr application,
- ApplicationManager& app_mngr) {
- using namespace smart_objects;
- using namespace hmi_apis;
-
- SmartObject msg_params = SmartObject(SmartType_Map);
- msg_params[strings::app_id] = application->app_id();
- msg_params[strings::name] = button;
- msg_params[strings::is_suscribed] = false;
-
- SmartObjectSPtr message = CreateMessageForHMI(
- hmi_apis::messageType::notification, app_mngr.GetNextHMICorrelationID());
- DCHECK(message);
-
- SmartObject& object = *message;
- object[strings::params][strings::function_id] =
- hmi_apis::FunctionID::Buttons_OnButtonSubscription;
-
- object[strings::msg_params] = msg_params;
-
- app_mngr.GetRPCService().ManageHMICommand(message);
-}
-
const VehicleData& MessageHelper::vehicle_data() {
return vehicle_data_;
}
@@ -1098,104 +1073,119 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateSetAppIcon(
return set_icon;
}
-void MessageHelper::SendOnButtonSubscriptionNotification(
- uint32_t app_id,
- hmi_apis::Common_ButtonName::eType button,
- bool is_subscribed,
- ApplicationManager& app_mngr) {
- using namespace smart_objects;
- using namespace hmi_apis;
+smart_objects::SmartObjectSPtr MessageHelper::CreateButtonNotificationToMobile(
+ ApplicationSharedPtr app,
+ const smart_objects::SmartObject& source_message) {
SDL_LOG_AUTO_TRACE();
- SmartObjectSPtr notification_ptr =
- std::make_shared<SmartObject>(SmartType_Map);
- if (!notification_ptr) {
- SDL_LOG_ERROR("Memory allocation failed.");
- return;
+ if (!app) {
+ SDL_LOG_ERROR("application NULL pointer");
+ return std::make_shared<smart_objects::SmartObject>(
+ smart_objects::SmartType_Null);
}
- SmartObject& notification = *notification_ptr;
- SmartObject msg_params = SmartObject(SmartType_Map);
- msg_params[strings::app_id] = app_id;
- msg_params[strings::name] = button;
- msg_params[strings::is_suscribed] = is_subscribed;
+ smart_objects::SmartObjectSPtr msg =
+ std::make_shared<smart_objects::SmartObject>(
+ smart_objects::SmartType_Map);
- notification[strings::params][strings::message_type] =
- static_cast<int32_t>(application_manager::MessageType::kNotification);
- notification[strings::params][strings::protocol_version] =
- commands::CommandImpl::protocol_version_;
- notification[strings::params][strings::protocol_type] =
- commands::CommandImpl::hmi_protocol_type_;
- notification[strings::params][strings::function_id] =
- hmi_apis::FunctionID::Buttons_OnButtonSubscription;
- notification[strings::msg_params] = msg_params;
+ smart_objects::SmartObject& ref = *msg;
+ ref[strings::params][strings::connection_key] = app->app_id();
+
+ const auto function_id = static_cast<mobile_apis::FunctionID::eType>(
+ source_message[strings::params][strings::function_id].asInt());
+ ref[strings::params][strings::function_id] = function_id;
+
+ mobile_apis::ButtonName::eType btn_id = mobile_apis::ButtonName::INVALID_ENUM;
- if (!app_mngr.GetRPCService().ManageHMICommand(notification_ptr)) {
- SDL_LOG_ERROR("Unable to send HMI notification");
+ if (source_message[strings::msg_params].keyExists(
+ hmi_response::button_name)) {
+ btn_id = static_cast<mobile_apis::ButtonName::eType>(
+ source_message[strings::msg_params][hmi_response::button_name].asInt());
+
+ } else if (source_message[strings::msg_params].keyExists(
+ strings::button_name)) {
+ btn_id = static_cast<mobile_apis::ButtonName::eType>(
+ source_message[strings::msg_params][strings::button_name].asInt());
}
-}
-void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp(
- ApplicationConstSharedPtr app, ApplicationManager& app_mngr) {
- using namespace smart_objects;
- using namespace hmi_apis;
- using namespace mobile_apis;
- SDL_LOG_AUTO_TRACE();
+ if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE &&
+ app->msg_version() <= utils::base_rpc_version) {
+ btn_id = mobile_apis::ButtonName::OK;
+ }
- if (app.use_count() == 0) {
- SDL_LOG_ERROR("Invalid application pointer ");
- return;
+ ref[strings::msg_params][strings::button_name] = btn_id;
+
+ auto get_mode_code = [&source_message](
+ const std::string& hmi_param_name,
+ const std::string& mobile_param_name) -> int64_t {
+ if (source_message[strings::msg_params].keyExists(hmi_param_name)) {
+ return source_message[strings::msg_params][hmi_param_name].asInt();
+ }
+
+ if (source_message[strings::msg_params].keyExists(mobile_param_name)) {
+ return source_message[strings::msg_params][mobile_param_name].asInt();
+ }
+
+ return -1;
+ };
+
+ if (mobile_apis::FunctionID::eType::OnButtonPressID == function_id) {
+ const auto press_mode = static_cast<mobile_apis::ButtonPressMode::eType>(
+ get_mode_code(hmi_response::button_mode, strings::button_press_mode));
+ ref[strings::msg_params][strings::button_press_mode] = press_mode;
}
- const ButtonSubscriptions subscriptions = app->SubscribedButtons().GetData();
- ButtonSubscriptions::iterator it = subscriptions.begin();
- for (; subscriptions.end() != it; ++it) {
- SendOnButtonSubscriptionNotification(
- app->hmi_app_id(),
- static_cast<Common_ButtonName::eType>(*it),
- true,
- app_mngr);
+ if (mobile_apis::FunctionID::eType::OnButtonEventID == function_id) {
+ const auto press_mode = static_cast<mobile_apis::ButtonEventMode::eType>(
+ get_mode_code(hmi_response::button_mode, strings::button_event_mode));
+ ref[strings::msg_params][strings::button_event_mode] = press_mode;
}
+
+ if (source_message[strings::msg_params].keyExists(
+ hmi_response::custom_button_id)) {
+ ref[strings::msg_params][strings::custom_button_id] =
+ source_message[strings::msg_params][strings::custom_button_id];
+ }
+
+ if (source_message[strings::msg_params].keyExists(strings::window_id)) {
+ ref[strings::msg_params][strings::window_id] =
+ source_message[strings::msg_params][strings::window_id];
+ }
+
+ return msg;
}
smart_objects::SmartObjectSPtr
-MessageHelper::CreateOnButtonSubscriptionNotification(
- uint32_t app_id,
- hmi_apis::Common_ButtonName::eType button,
- bool is_subscribed) {
+MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ const uint32_t app_id,
+ const hmi_apis::Common_ButtonName::eType button_name,
+ const hmi_apis::FunctionID::eType function_id,
+ application_manager::ApplicationManager& app_mngr) {
using namespace smart_objects;
- using namespace hmi_apis;
SDL_LOG_AUTO_TRACE();
- SmartObjectSPtr notification_ptr =
- std::make_shared<SmartObject>(SmartType_Map);
- SmartObject& notification = *notification_ptr;
+
+ SmartObjectSPtr request_ptr = CreateMessageForHMI(
+ hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID());
+
+ SmartObject& request = *request_ptr;
SmartObject msg_params = SmartObject(SmartType_Map);
msg_params[strings::app_id] = app_id;
- msg_params[strings::name] = button;
- msg_params[strings::is_suscribed] = is_subscribed;
- notification[strings::params][strings::message_type] =
- static_cast<int32_t>(application_manager::MessageType::kNotification);
- notification[strings::params][strings::protocol_version] =
- commands::CommandImpl::protocol_version_;
- notification[strings::params][strings::protocol_type] =
- commands::CommandImpl::hmi_protocol_type_;
- notification[strings::params][strings::function_id] =
- hmi_apis::FunctionID::Buttons_OnButtonSubscription;
- notification[strings::msg_params] = msg_params;
- return notification_ptr;
+ msg_params[strings::button_name] = button_name;
+ request[strings::params][strings::function_id] = function_id;
+ request[strings::msg_params] = msg_params;
+ return request_ptr;
}
smart_objects::SmartObjectList
-MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
+MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
ApplicationConstSharedPtr app,
- ApplicationManager& app_mngr,
- const ButtonSubscriptions& button_subscriptions) {
- using namespace smart_objects;
+ const ButtonSubscriptions& button_subscriptions,
+ const hmi_apis::FunctionID::eType function_id,
+ ApplicationManager& app_mngr) {
using namespace hmi_apis;
- using namespace mobile_apis;
SDL_LOG_AUTO_TRACE();
- SmartObjectList button_subscription_requests;
+ smart_objects::SmartObjectList button_subscription_requests;
if (app.use_count() == 0) {
SDL_LOG_ERROR("Invalid application pointer ");
@@ -1207,7 +1197,8 @@ MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
static_cast<Common_ButtonName::eType>(it);
button_subscription_requests.push_back(
- CreateOnButtonSubscriptionNotification(app->hmi_app_id(), btn, true));
+ CreateButtonSubscriptionHandlingRequestToHmi(
+ app->app_id(), btn, function_id, app_mngr));
}
return button_subscription_requests;
diff --git a/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc b/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc
index 18b1f8a2a3..598b7a6ccb 100644
--- a/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_processor_impl.cc
@@ -162,6 +162,11 @@ void ResumptionDataProcessorImpl::ProcessResumptionStatus(
CheckVehicleDataResponse(found_request.message, response, status);
}
+ if (hmi_apis::FunctionID::Buttons_SubscribeButton ==
+ found_request.request_id.function_id) {
+ ProcessSubscribeButtonResponse(app_id, found_request.message, response);
+ }
+
if (hmi_apis::FunctionID::UI_CreateWindow ==
found_request.request_id.function_id) {
CheckCreateWindowResponse(found_request.message, response);
@@ -857,6 +862,7 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions(
const smart_objects::SmartObject& subscriptions =
saved_app[strings::application_subscriptions];
+ ButtonSubscriptions button_subscriptions;
if (subscriptions.keyExists(strings::application_buttons)) {
const smart_objects::SmartObject& subscriptions_buttons =
subscriptions[strings::application_buttons];
@@ -864,31 +870,20 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions(
for (size_t i = 0; i < subscriptions_buttons.length(); ++i) {
btn = static_cast<mobile_apis::ButtonName::eType>(
(subscriptions_buttons[i]).asInt());
- application->SubscribeToButton(btn);
+ if (mobile_apis::ButtonName::CUSTOM_BUTTON != btn) {
+ button_subscriptions.insert(btn);
+ }
}
- ButtonSubscriptions button_subscriptions =
- GetButtonSubscriptionsToResume(application);
-
ProcessMessagesToHMI(
- MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
- application, application_manager_, button_subscriptions));
+ MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
+ application,
+ button_subscriptions,
+ hmi_apis::FunctionID::Buttons_SubscribeButton,
+ application_manager_));
}
}
-ButtonSubscriptions ResumptionDataProcessorImpl::GetButtonSubscriptionsToResume(
- ApplicationSharedPtr application) const {
- ButtonSubscriptions button_subscriptions =
- application->SubscribedButtons().GetData();
- auto it = button_subscriptions.find(mobile_apis::ButtonName::CUSTOM_BUTTON);
-
- if (it != button_subscriptions.end()) {
- button_subscriptions.erase(it);
- }
-
- return button_subscriptions;
-}
-
void ResumptionDataProcessorImpl::AddPluginsSubscriptions(
ApplicationSharedPtr application,
const smart_objects::SmartObject& saved_app) {
@@ -916,11 +911,13 @@ void ResumptionDataProcessorImpl::DeleteButtonsSubscriptions(
if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == hmi_btn) {
continue;
}
- auto notification = MessageHelper::CreateOnButtonSubscriptionNotification(
- application->hmi_app_id(), hmi_btn, false);
- // is_subscribed = false
- ProcessMessageToHMI(notification, false);
- application->UnsubscribeFromButton(btn);
+ smart_objects::SmartObjectSPtr unsubscribe_request =
+ MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ application->app_id(),
+ hmi_btn,
+ hmi_apis::FunctionID::Buttons_UnsubscribeButton,
+ application_manager_);
+ ProcessMessageToHMI(unsubscribe_request, false);
}
}
@@ -1007,7 +1004,7 @@ bool IsResponseSuccessful(const smart_objects::SmartObject& response) {
response[strings::params][application_manager::hmi_response::code]
.asInt());
- return commands::CommandRequestImpl::IsHMIResultSuccess(result_code) ||
+ return commands::IsHMIResultSuccess(result_code) ||
hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code;
}
@@ -1046,6 +1043,26 @@ void ResumptionDataProcessorImpl::CheckVehicleDataResponse(
}
}
+void ResumptionDataProcessorImpl::ProcessSubscribeButtonResponse(
+ const uint32_t app_id,
+ const smart_objects::SmartObject& request,
+ const smart_objects::SmartObject& response) {
+ SDL_LOG_AUTO_TRACE();
+ if (!IsResponseSuccessful(response)) {
+ return;
+ }
+
+ ApplicationSharedPtr app = application_manager_.application(app_id);
+ if (!app) {
+ SDL_LOG_ERROR("NULL pointer.");
+ return;
+ }
+ const mobile_apis::ButtonName::eType btn_id =
+ static_cast<mobile_apis::ButtonName::eType>(
+ request[strings::msg_params][strings::button_name].asInt());
+ app->SubscribeToButton(btn_id);
+}
+
void ResumptionDataProcessorImpl::CheckModuleDataSubscription(
const ns_smart_device_link::ns_smart_objects::SmartObject& request,
const ns_smart_device_link::ns_smart_objects::SmartObject& response,
diff --git a/src/components/application_manager/test/application_helper_test.cc b/src/components/application_manager/test/application_helper_test.cc
index 5c6d3b22f6..1f1a76298c 100644
--- a/src/components/application_manager/test/application_helper_test.cc
+++ b/src/components/application_manager/test/application_helper_test.cc
@@ -149,7 +149,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) {
const uint32_t cmd_id = 1;
const uint32_t menu_id = 2;
const uint32_t choice_set_id = 3;
- const mobile_apis::ButtonName::eType button = mobile_apis::ButtonName::AC;
smart_objects::SmartObject cmd(smart_objects::SmartType_Map);
cmd[strings::msg_params][strings::cmd_id] = cmd_id;
@@ -163,8 +162,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) {
app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]);
app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]);
- EXPECT_TRUE(app_impl_->SubscribeToButton(button));
-
const std::string some_string = "some_string";
smart_objects::SmartObject dummy_data =
smart_objects::SmartObject(smart_objects::SmartType_String);
@@ -191,7 +188,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) {
EXPECT_TRUE(smart_objects::SmartType_Null != sub_menu1.getType());
const auto choice_set1 = app_impl_->FindChoiceSet(choice_set_id);
EXPECT_TRUE(smart_objects::SmartType_Null != choice_set1.getType());
- EXPECT_TRUE(app_impl_->IsSubscribedToButton(button));
auto help_prompt = app_impl_->help_prompt();
EXPECT_TRUE(help_prompt->asString() == some_string);
auto timeout_prompt = app_impl_->timeout_prompt();
@@ -227,7 +223,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) {
EXPECT_TRUE(smart_objects::SmartType_Null == sub_menu2.getType());
const auto choice_set2 = app_impl_->FindChoiceSet(choice_set_id);
EXPECT_TRUE(smart_objects::SmartType_Null == choice_set2.getType());
- EXPECT_FALSE(app_impl_->IsSubscribedToButton(button));
help_prompt = app_impl_->help_prompt();
EXPECT_FALSE(help_prompt->asString() == some_string);
timeout_prompt = app_impl_->timeout_prompt();
@@ -261,7 +256,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) {
app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]);
app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]);
app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]);
- app_impl_->SubscribeToButton(mobile_apis::ButtonName::AC);
EXPECT_CALL(*mock_message_helper_, CreateDeleteUICommandRequest(_, _, _))
.WillOnce(Return(std::make_shared<smart_objects::SmartObject>()));
@@ -275,9 +269,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) {
EXPECT_CALL(*mock_message_helper_, SendResetPropertiesRequest(_, _));
- EXPECT_CALL(*mock_message_helper_,
- SendUnsubscribeButtonNotification(_, _, _));
-
// Act
application_manager::DeleteApplicationData(app_impl_, app_manager_impl_);
}
diff --git a/src/components/application_manager/test/application_impl_test.cc b/src/components/application_manager/test/application_impl_test.cc
index 5f23e97391..1e58ce8636 100644
--- a/src/components/application_manager/test/application_impl_test.cc
+++ b/src/components/application_manager/test/application_impl_test.cc
@@ -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) {
diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
index 82a0574c7f..9e69b0bcd6 100644
--- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h
+++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
@@ -125,11 +125,12 @@ class MockMessageHelper {
MOCK_METHOD2(CreateHMIStatusNotification,
smart_objects::SmartObjectSPtr(ApplicationSharedPtr application,
const WindowID window_id));
- MOCK_METHOD3(CreateOnButtonSubscriptionNotificationsForApp,
+ MOCK_METHOD4(CreateButtonSubscriptionsHandlingRequestsList,
smart_objects::SmartObjectList(
ApplicationConstSharedPtr application,
- ApplicationManager& app_mngr,
- const ButtonSubscriptions& button_subscriptions));
+ const ButtonSubscriptions& button_subscriptions,
+ const hmi_apis::FunctionID::eType function_id,
+ ApplicationManager& app_mngr));
MOCK_METHOD4(SendPolicyUpdate,
void(const std::string& file_path,
const uint32_t timeout,
@@ -172,9 +173,6 @@ class MockMessageHelper {
MOCK_METHOD2(CreateModuleInfoSO,
smart_objects::SmartObjectSPtr(uint32_t function_id,
ApplicationManager& app_mngr));
- MOCK_METHOD2(SendAllOnButtonSubscriptionNotificationsForApp,
- void(ApplicationConstSharedPtr app,
- ApplicationManager& app_mngr));
MOCK_METHOD2(CreateUIResetGlobalPropertiesRequest,
smart_objects::SmartObjectSPtr(
const ResetGlobalPropertiesResult& reset_result,
@@ -196,11 +194,18 @@ class MockMessageHelper {
MOCK_METHOD1(CreateSubscribeWayPointsMessageToHMI,
smart_objects::SmartObjectSPtr(const uint32_t correlation_id));
- MOCK_METHOD3(
- CreateOnButtonSubscriptionNotification,
- smart_objects::SmartObjectSPtr(uint32_t app_id,
- hmi_apis::Common_ButtonName::eType button,
- bool is_subscribed));
+ MOCK_METHOD4(CreateButtonSubscriptionHandlingRequestToHmi,
+ smart_objects::SmartObjectSPtr(
+ const uint32_t app_id,
+ const hmi_apis::Common_ButtonName::eType button_name,
+ const hmi_apis::FunctionID::eType function_id,
+ application_manager::ApplicationManager& app_mngr));
+
+ MOCK_METHOD2(CreateButtonNotificationToMobile,
+ smart_objects::SmartObjectSPtr(
+ ApplicationSharedPtr app,
+ const smart_objects::SmartObject& source_message));
+
MOCK_METHOD2(SendOnResumeAudioSourceToHMI,
void(uint32_t app_id, ApplicationManager& app_mngr));
MOCK_METHOD2(CreateAddSubMenuRequestsToHMI,
@@ -352,10 +357,6 @@ class MockMessageHelper {
MOCK_METHOD2(SendResetPropertiesRequest,
void(ApplicationSharedPtr application,
ApplicationManager& app_mngr));
- MOCK_METHOD3(SendUnsubscribeButtonNotification,
- void(mobile_apis::ButtonName::eType button,
- ApplicationSharedPtr application,
- ApplicationManager& app_mngr));
MOCK_METHOD1(CreateAppServiceCapabilities,
smart_objects::SmartObject(
std::vector<smart_objects::SmartObject>& all_services));
diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc
index 3cab2be0fb..02cf70e3ba 100644
--- a/src/components/application_manager/test/mock_message_helper.cc
+++ b/src/components/application_manager/test/mock_message_helper.cc
@@ -269,11 +269,6 @@ MockMessageHelper* MockMessageHelper::message_helper_mock() {
static ::testing::NiceMock<MockMessageHelper> message_helper_mock;
return &message_helper_mock;
}
-void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp(
- ApplicationConstSharedPtr app, ApplicationManager& app_mngr) {
- MockMessageHelper::message_helper_mock()
- ->SendAllOnButtonSubscriptionNotificationsForApp(app, app_mngr);
-}
void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id,
ApplicationManager& app_mngr) {
@@ -600,30 +595,32 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI(
}
smart_objects::SmartObjectSPtr
-MessageHelper::CreateOnButtonSubscriptionNotification(
- uint32_t app_id,
- hmi_apis::Common_ButtonName::eType button,
- bool is_subscribed) {
+MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
+ const uint32_t app_id,
+ const hmi_apis::Common_ButtonName::eType button_name,
+ const hmi_apis::FunctionID::eType function_id,
+ ApplicationManager& app_mngr) {
return MockMessageHelper::message_helper_mock()
- ->CreateOnButtonSubscriptionNotification(app_id, button, is_subscribed);
+ ->CreateButtonSubscriptionHandlingRequestToHmi(
+ app_id, button_name, function_id, app_mngr);
}
-smart_objects::SmartObjectList
-MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
- ApplicationConstSharedPtr application,
- ApplicationManager& app_mngr,
- const ButtonSubscriptions& button_subscriptions) {
+smart_objects::SmartObjectSPtr MessageHelper::CreateButtonNotificationToMobile(
+ ApplicationSharedPtr app,
+ const smart_objects::SmartObject& source_message) {
return MockMessageHelper::message_helper_mock()
- ->CreateOnButtonSubscriptionNotificationsForApp(
- application, app_mngr, button_subscriptions);
+ ->CreateButtonNotificationToMobile(app, source_message);
}
-void MessageHelper::SendUnsubscribeButtonNotification(
- mobile_apis::ButtonName::eType button,
- ApplicationSharedPtr application,
+smart_objects::SmartObjectList
+MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
+ ApplicationConstSharedPtr app,
+ const ButtonSubscriptions& button_subscriptions,
+ const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr) {
return MockMessageHelper::message_helper_mock()
- ->SendUnsubscribeButtonNotification(button, application, app_mngr);
+ ->CreateButtonSubscriptionsHandlingRequestsList(
+ app, button_subscriptions, function_id, app_mngr);
}
smart_objects::SmartObject MessageHelper::CreateAppServiceCapabilities(
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 f5ccd99ee0..1ff04c332c 100644
--- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc
+++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc
@@ -604,19 +604,13 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) {
ON_CALL(*mock_app_, SubscribedButtons())
.WillByDefault(Return(button_subscription_accessor));
- smart_objects::SmartObjectList button_subscription_notifications;
+ smart_objects::SmartObjectList button_subscription_requests_list;
ON_CALL(*application_manager::MockMessageHelper::message_helper_mock(),
- CreateOnButtonSubscriptionNotificationsForApp(_, _, _))
- .WillByDefault(Return(button_subscription_notifications));
+ CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _))
+ .WillByDefault(Return(button_subscription_requests_list));
EXPECT_CALL(*mock_app_, set_grammar_id(kTestGrammarId_));
- for (uint32_t i = 0; i < count_of_buttons; ++i) {
- EXPECT_CALL(
- *mock_app_,
- SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(i)));
- }
-
std::list<application_manager::AppExtensionPtr> extensions;
extensions.insert(extensions.begin(), mock_app_extension_);
@@ -624,7 +618,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) {
EXPECT_CALL(*mock_app_extension_, ProcessResumption(saved_app));
EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(),
- CreateOnButtonSubscriptionNotificationsForApp(_, _, _));
+ CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _));
const bool res = res_ctrl_->StartResumption(mock_app_, kHash_, callback_);
EXPECT_TRUE(res);
diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h
index 708bf8b048..72a322f336 100644
--- a/src/components/include/application_manager/application_manager.h
+++ b/src/components/include/application_manager/application_manager.h
@@ -119,6 +119,11 @@ struct ApplicationsPolicyAppIdSorter {
}
};
+struct ExpiredButtonRequestData {
+ uint32_t app_id_;
+ hmi_apis::Common_ButtonName::eType button_name_;
+};
+
typedef std::set<ApplicationSharedPtr, ApplicationsSorter> ApplicationSet;
typedef std::set<ApplicationSharedPtr, ApplicationsPolicyAppIdSorter>
@@ -947,6 +952,35 @@ class ApplicationManager {
*/
virtual bool UnsubscribeAppFromSoftButtons(
const commands::MessageSharedPtr response_message) = 0;
+
+ /**
+ * @brief Save subscribe/unsubscribe button request after timeout to ensure
+ * possibility to align mobile subscription/unsubscription status with actual
+ * subscription/unsubscription status on HMI
+ * @param app_id Application id from request message
+ * @param corr_id Correlation id
+ * @param button_name name of button to subscribe/unsubscribe
+ */
+ virtual void AddExpiredButtonRequest(
+ const uint32_t app_id,
+ const int32_t corr_id,
+ const hmi_apis::Common_ButtonName::eType button_name) = 0;
+
+ /**
+ * @brief Return optional structure with information regarding
+ * subscribe/unsubscribe button request data
+ * @param corr_id Correlation id
+ * @return optional structure with subscribe/unsubscribe button request data
+ */
+ virtual utils::Optional<ExpiredButtonRequestData> GetExpiredButtonRequestData(
+ const int32_t corr_id) const = 0;
+
+ /**
+ * @brief Delete data about already processed expired subscribe/unsubscribe
+ * button request in case if HMI send response to expired request
+ * @param corr_id Correlation id
+ */
+ virtual void DeleteExpiredButtonRequest(const int32_t corr_id) = 0;
};
} // namespace application_manager
diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h
index 525197cb49..116d758ec4 100644
--- a/src/components/include/test/application_manager/mock_application_manager.h
+++ b/src/components/include/test/application_manager/mock_application_manager.h
@@ -396,6 +396,15 @@ class MockApplicationManager : public application_manager::ApplicationManager {
MOCK_CONST_METHOD0(GetCommandFactory, application_manager::CommandFactory&());
MOCK_CONST_METHOD0(get_current_audio_source, uint32_t());
MOCK_METHOD1(set_current_audio_source, void(const uint32_t));
+ MOCK_METHOD3(AddExpiredButtonRequest,
+ void(const uint32_t app_id,
+ const int32_t corr_id,
+ const hmi_apis::Common_ButtonName::eType button_name));
+ MOCK_CONST_METHOD1(
+ GetExpiredButtonRequestData,
+ utils::Optional<application_manager::ExpiredButtonRequestData>(
+ const int32_t corr_id));
+ MOCK_METHOD1(DeleteExpiredButtonRequest, void(const int32_t corr_id));
};
} // namespace application_manager_test
diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml
index 9b09f239fe..f5a8ce163d 100644
--- a/src/components/interfaces/HMI_API.xml
+++ b/src/components/interfaces/HMI_API.xml
@@ -4546,24 +4546,30 @@
</description>
</param>
</function>
- <function name="OnButtonSubscription" messagetype="notification">
+ <function name="SubscribeButton" messagetype="request">
<description>
- Sender: SDL->HMI. Purpose: to notify about button subscription state is changed for the named application
+ Subscribes to buttons.
</description>
- <param name="name" type="Common.ButtonName" mandatory="true" />
- <param name="isSubscribed" type="Boolean" mandatory="true">
- <description>
- Defines whether the named button has status of 'subscribed' or 'unsubscribed':
- If "true" - the named button is subscribed.
- If "false" - the named button is unsubscribed.
- </description>
+ <param name="appID" type="Integer" mandatory="true">
+ <description>The ID of the application requesting this button subscription. </description>
</param>
+ <param name="buttonName" type="Common.ButtonName" mandatory="true">
+ <description>Name of the button to subscribe.</description>
+ </param>
+ </function>
+ <function name="SubscribeButton" messagetype="response"> </function>
+ <function name="UnsubscribeButton" messagetype="request">
+ <description>
+ Unsubscribes from buttons.
+ </description>
<param name="appID" type="Integer" mandatory="true">
- <description>
- The ID of application that relates to this button-subscription status change.
- </description>
+ <description>The ID of the application requesting this button unsubscription. </description>
+ </param>
+ <param name="buttonName" type="Common.ButtonName" mandatory="true">
+ <description>Name of the button to unsubscribe from.</description>
</param>
</function>
+ <function name="UnsubscribeButton" messagetype="response"></function>
</interface>
<interface name="BasicCommunication" version="2.2.0" date="2021-04-14">