From baf63cadaa6ce045b4915222601a377e86daf442 Mon Sep 17 00:00:00 2001 From: Jacob Keeler Date: Thu, 18 Jun 2020 11:09:42 -0400 Subject: Fix Handshake Flow issues (#3441) * Fix issue with External PTU timeout When attempting to start an encrypted service, the mobile proxy would not receive a response if the PTU timed out. This is because the retry count is based on the number of OnSystemRequests received from the HMI. Since that number would never exceed the number of retries, `IsAllowedRetryCountExceeded` would never return false. This will now return false after the final retry times out. * Add error code check in ProcessInternalError If the proxy responds with NOT_SUPPORTED or SSL_INVALID_DATA, Core will mark the handshake as failed. --- .../policy_external/src/policy_manager_impl.cc | 2 +- .../security_manager/security_manager_impl.h | 4 +-- .../security_manager/src/security_manager_impl.cc | 40 ++++++++++++---------- .../security_manager/test/security_manager_test.cc | 11 +++--- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 082d4a37ba..12ab1224fd 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -1368,7 +1368,7 @@ bool PolicyManagerImpl::IsAllowedRetryCountExceeded() const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(retry_sequence_lock_); - return retry_sequence_index_ > retry_sequence_seconds_.size(); + return retry_sequence_index_ >= retry_sequence_seconds_.size(); } void PolicyManagerImpl::IncrementRetryIndex() { diff --git a/src/components/security_manager/include/security_manager/security_manager_impl.h b/src/components/security_manager/include/security_manager/security_manager_impl.h index ee00e0774a..6e5fb08c20 100644 --- a/src/components/security_manager/include/security_manager/security_manager_impl.h +++ b/src/components/security_manager/include/security_manager/security_manager_impl.h @@ -241,12 +241,12 @@ class SecurityManagerImpl : public SecurityManager, * \brief Parse SecurityMessage as HandshakeData request * \param inMessage SecurityMessage with binary data of handshake */ - bool ProccessHandshakeData(const SecurityMessage& inMessage); + bool ProcessHandshakeData(const SecurityMessage& inMessage); /** * \brief Parse InternalError from mobile side * \param inMessage SecurityMessage with binary data of handshake */ - bool ProccessInternalError(const SecurityMessage& inMessage); + bool ProcessInternalError(const SecurityMessage& inMessage); /** * \brief Sends security query diff --git a/src/components/security_manager/src/security_manager_impl.cc b/src/components/security_manager/src/security_manager_impl.cc index a24e48289d..5ae8c35084 100644 --- a/src/components/security_manager/src/security_manager_impl.cc +++ b/src/components/security_manager/src/security_manager_impl.cc @@ -128,12 +128,12 @@ void SecurityManagerImpl::Handle(const SecurityMessage message) { } switch (message->get_header().query_id) { case SecurityQuery::SEND_HANDSHAKE_DATA: - if (!ProccessHandshakeData(message)) { - LOG4CXX_ERROR(logger_, "Proccess HandshakeData failed"); + if (!ProcessHandshakeData(message)) { + LOG4CXX_ERROR(logger_, "Process HandshakeData failed"); } break; case SecurityQuery::SEND_INTERNAL_ERROR: - if (!ProccessInternalError(message)) { + if (!ProcessInternalError(message)) { LOG4CXX_ERROR(logger_, "Processing income InternalError failed"); } break; @@ -515,7 +515,7 @@ bool SecurityManagerImpl::IsPolicyCertificateDataEmpty() { return false; } -bool SecurityManagerImpl::ProccessHandshakeData( +bool SecurityManagerImpl::ProcessHandshakeData( const SecurityMessage& inMessage) { LOG4CXX_INFO(logger_, "SendHandshakeData processing"); DCHECK(inMessage); @@ -556,11 +556,11 @@ bool SecurityManagerImpl::ProccessHandshakeData( &out_data_size); if (handshake_result == SSLContext::Handshake_Result_AbnormalFail) { // Do not return handshake data on AbnormalFail or null returned values - const std::string erorr_text(sslContext->LastError()); + const std::string error_text(sslContext->LastError()); LOG4CXX_ERROR(logger_, - "SendHandshakeData: Handshake failed: " << erorr_text); + "SendHandshakeData: Handshake failed: " << error_text); SendInternalError( - connection_key, ERROR_SSL_INVALID_DATA, erorr_text, seqNumber); + connection_key, ERROR_SSL_INVALID_DATA, error_text, seqNumber); NotifyListenersOnHandshakeDone(connection_key, SSLContext::Handshake_Result_Fail); // no handshake data to send @@ -584,25 +584,29 @@ bool SecurityManagerImpl::ProccessHandshakeData( return true; } -bool SecurityManagerImpl::ProccessInternalError( +bool SecurityManagerImpl::ProcessInternalError( const SecurityMessage& inMessage) { - LOG4CXX_INFO(logger_, - "Received InternalError with Json message" - << inMessage->get_json_message()); - Json::Value root; std::string str = inMessage->get_json_message(); + const uint32_t connection_key = inMessage->get_connection_key(); + LOG4CXX_INFO(logger_, "Received InternalError with Json message" << str); + Json::Value root; utils::JsonReader reader; if (!reader.parse(str, &root)) { LOG4CXX_DEBUG(logger_, "Json parsing fails."); return false; } + uint8_t id = root[kErrId].asInt(); LOG4CXX_DEBUG(logger_, - "Received InternalError id " - << root[kErrId].asString() - << ", text: " << root[kErrText].asString()); + "Received InternalError id " << std::to_string(id) << ", text: " + << root[kErrText].asString()); + if (ERROR_SSL_INVALID_DATA == id || ERROR_NOT_SUPPORTED == id) { + NotifyListenersOnHandshakeDone(connection_key, + SSLContext::Handshake_Result_Fail); + } return true; } + void SecurityManagerImpl::SendHandshakeBinData(const uint32_t connection_key, const uint8_t* const data, const size_t data_size, @@ -619,11 +623,11 @@ void SecurityManagerImpl::SendHandshakeBinData(const uint32_t connection_key, void SecurityManagerImpl::SendInternalError(const uint32_t connection_key, const uint8_t& error_id, - const std::string& erorr_text, + const std::string& error_text, const uint32_t seq_number) { Json::Value value; value[kErrId] = error_id; - value[kErrText] = erorr_text; + value[kErrText] = error_text; const std::string error_str = value.toStyledString(); SecurityQuery::QueryHeader header( SecurityQuery::NOTIFICATION, @@ -642,7 +646,7 @@ void SecurityManagerImpl::SendInternalError(const uint32_t connection_key, SendQuery(query, connection_key); LOG4CXX_DEBUG(logger_, "Sent Internal error id " << static_cast(error_id) - << " : \"" << erorr_text << "\"."); + << " : \"" << error_text << "\"."); } void SecurityManagerImpl::SendQuery(const SecurityQuery& query, diff --git a/src/components/security_manager/test/security_manager_test.cc b/src/components/security_manager/test/security_manager_test.cc index 7906ae7006..0cbe204f38 100644 --- a/src/components/security_manager/test/security_manager_test.cc +++ b/src/components/security_manager/test/security_manager_test.cc @@ -571,7 +571,7 @@ TEST_F(SecurityManagerTest, StartHandshake_SSLInternalError) { * Shall send InternallError on * getting SEND_HANDSHAKE_DATA with NULL data */ -TEST_F(SecurityManagerTest, ProccessHandshakeData_WrongDataSize) { +TEST_F(SecurityManagerTest, ProcessHandshakeData_WrongDataSize) { SetMockCryptoManager(); uint32_t connection_id = 0; uint8_t session_id = 0; @@ -600,8 +600,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_WrongDataSize) { * getting SEND_HANDSHAKE_DATA from mobile side * for service which is not protected */ -TEST_F(SecurityManagerTest, - DISABLED_ProccessHandshakeData_ServiceNotProtected) { +TEST_F(SecurityManagerTest, DISABLED_ProcessHandshakeData_ServiceNotProtected) { SetMockCryptoManager(); // Expect InternalError with ERROR_ID uint32_t connection_id = 0; @@ -649,7 +648,7 @@ TEST_F(SecurityManagerTest, * SEND_HANDSHAKE_DATA from mobile side with invalid handshake * data (DoHandshakeStep return NULL pointer) */ -TEST_F(SecurityManagerTest, ProccessHandshakeData_InvalidData) { +TEST_F(SecurityManagerTest, ProcessHandshakeData_InvalidData) { SetMockCryptoManager(); // Count handshake calls @@ -732,7 +731,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_InvalidData) { * Shall send HandshakeData on getting SEND_HANDSHAKE_DATA from mobile side * with correct handshake data Check Fail and sussecc states */ -TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) { +TEST_F(SecurityManagerTest, ProcessHandshakeData_Answer) { SetMockCryptoManager(); // Count handshake calls const int handshake_emulates = 2; @@ -808,7 +807,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) { * and return handshake data * Check Fail and sussecc states */ -TEST_F(SecurityManagerTest, ProccessHandshakeData_HandshakeFinished) { +TEST_F(SecurityManagerTest, ProcessHandshakeData_HandshakeFinished) { SetMockCryptoManager(); // Count handshake calls const int handshake_emulates = 6; -- cgit v1.2.1 From 137d3288abb75af3233e0a7271f5351132ddac3d Mon Sep 17 00:00:00 2001 From: "Alexander Kutsan (GitHub)" Date: Thu, 18 Jun 2020 18:12:58 +0300 Subject: Fix potential deadlock in PolicyHandler (#3383) SYNC-10345 There was a vulnerability in the PolicyHandler which causes a mutex deadlock. For example - MessageLoop thread of RpcService handles incoming messages. In case when SDL receives AllowSDLFunctionality notification, this thread calls OnAllowSDLFunctionalityNotification inside PolicyHandler. At some point of time this function captures accessor from AM which holds applications_list_lock_ there. At this moment thread AM Pool 0 of RequestController processes some RPC from queue and captures policy_manager_lock_ in PolicyHandler. After that at some moment thread AM Pool 0 tries to get application shared pointer from AM and locks itself as this mutex are already locked with thread MessageLoop. Also, MessageLoop thread at some moment tries to acquire policy_manager_lock_ and locks itself as this mutex are already locked with thread AM Pool 0, which is waiting for applications_list_lock_ to unlock. As a result we have a classical thread deadlock after which SDL stuck forewer. To avoid such situations, there was analyzed all bottlenecks related to applications_list_lock_ and its accessors. Accessors were scoped in several places to avoid similar deadlocks in future. Co-authored-by: Elvis Kuliiev --- .../application_manager/src/policies/policy_handler.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 85d6858b0d..646d523cf4 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1310,18 +1310,22 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( #ifdef EXTERNAL_PROPRIETARY_MODE - DataAccessor accessor = - application_manager_.applications(); + ApplicationSet applications; + { + DataAccessor accessor = + application_manager_.applications(); + applications = accessor.GetData(); + } if (!is_allowed) { std::for_each( - accessor.GetData().begin(), - accessor.GetData().end(), + applications.begin(), + applications.end(), DeactivateApplication(device_handle, application_manager_.state_controller())); } else { std::for_each( - accessor.GetData().begin(), - accessor.GetData().end(), + applications.begin(), + applications.end(), SDLAlowedNotification(device_handle, policy_manager_.get(), application_manager_.state_controller())); -- cgit v1.2.1 From debe7f40ccccfe3f2d84ec94a6fee10a9988796b Mon Sep 17 00:00:00 2001 From: Collin Date: Fri, 19 Jun 2020 06:01:48 -0700 Subject: Add Destructor to BluetoothTransportAdapter (#3442) prevent override of bluetooth destructor so that the default transport adapter destructor impl will be called --- .../transport_manager/bluetooth/bluetooth_transport_adapter.h | 5 ----- .../transport_manager/src/bluetooth/bluetooth_transport_adapter.cc | 2 -- 2 files changed, 7 deletions(-) diff --git a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h index 14f954286f..5429f50f7f 100644 --- a/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h +++ b/src/components/transport_manager/include/transport_manager/bluetooth/bluetooth_transport_adapter.h @@ -56,11 +56,6 @@ class BluetoothTransportAdapter : public TransportAdapterImpl { BluetoothTransportAdapter(resumption::LastState&, const TransportManagerSettings& settings); - /** - * @brief Destructor. - */ - virtual ~BluetoothTransportAdapter(); - protected: /** * @brief Return type of device. diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc b/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc index 066751c474..41e77af5bd 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc @@ -54,8 +54,6 @@ namespace transport_adapter { CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager") -BluetoothTransportAdapter::~BluetoothTransportAdapter() {} - BluetoothTransportAdapter::BluetoothTransportAdapter( resumption::LastStateWrapperPtr last_state_wrapper, const TransportManagerSettings& settings) -- cgit v1.2.1 From 67b92faf0c03d5186014e346b4f607cedc3f47f2 Mon Sep 17 00:00:00 2001 From: "Alexander Kutsan (GitHub)" Date: Tue, 23 Jun 2020 00:57:06 +0300 Subject: Fixes race condition in messagemeter.h (#3377) SDLCORE-373 Unprotected critical section accessed by two different threads, timing_map was being modified by clearing the map identifiers causing a crash in boost::date_time Review: Change RWLock to Lock, Added FrequencyImpl private method Co-authored-by: Mario Godinez --- src/components/include/utils/messagemeter.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/include/utils/messagemeter.h b/src/components/include/utils/messagemeter.h index 1148a65b57..fb70839640 100644 --- a/src/components/include/utils/messagemeter.h +++ b/src/components/include/utils/messagemeter.h @@ -37,8 +37,11 @@ #include #include #include "utils/date_time.h" +#include "utils/lock.h" namespace utils { + +CREATE_LOGGERPTR_GLOBAL(logger_, "MessageMeter") /** @brief The MessageMeter class need to count message frequency Default time range value is 1 second @@ -86,10 +89,13 @@ class MessageMeter { date_time::TimeDuration time_range() const; private: + size_t FrequencyImpl(const Id& id); + date_time::TimeDuration time_range_; typedef std::multiset Timings; typedef std::map TimingMap; TimingMap timing_map_; + sync_primitives::Lock timing_map_lock_; }; template @@ -99,22 +105,33 @@ MessageMeter::MessageMeter() { template size_t MessageMeter::TrackMessage(const Id& id) { + LOG4CXX_AUTO_TRACE(logger_); return TrackMessages(id, 1); } template size_t MessageMeter::TrackMessages(const Id& id, const size_t count) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(timing_map_lock_); Timings& timings = timing_map_[id]; const date_time::TimeDuration current_time = date_time::getCurrentTime(); for (size_t i = 0; i < count; ++i) { // Adding to the end is amortized constant timings.insert(timings.end(), current_time); } - return Frequency(id); + return FrequencyImpl(id); } template size_t MessageMeter::Frequency(const Id& id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(timing_map_lock_); + return FrequencyImpl(id); +} + +template +size_t MessageMeter::FrequencyImpl(const Id& id) { + LOG4CXX_AUTO_TRACE(logger_); typename TimingMap::iterator it = timing_map_.find(id); if (it == timing_map_.end()) { return 0u; @@ -131,21 +148,27 @@ size_t MessageMeter::Frequency(const Id& id) { template void MessageMeter::RemoveIdentifier(const Id& id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(timing_map_lock_); timing_map_.erase(id); } template void MessageMeter::ClearIdentifiers() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(timing_map_lock_); timing_map_.clear(); } template void MessageMeter::set_time_range(const size_t time_range_msecs) { + LOG4CXX_AUTO_TRACE(logger_); time_range_ = date_time::milliseconds(time_range_msecs); } template void MessageMeter::set_time_range( const date_time::TimeDuration& time_range) { + LOG4CXX_AUTO_TRACE(logger_); time_range_ = time_range; } template -- cgit v1.2.1 From 73840c947b176476a7a68642d4a78cd270e270c1 Mon Sep 17 00:00:00 2001 From: Collin Date: Tue, 23 Jun 2020 11:05:42 -0700 Subject: add DEPRECATED notice to OnFindApplications (#3451) --- src/components/interfaces/HMI_API.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 197bdee44a..7fd1b8fd1b 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -4331,6 +4331,7 @@ This method must be invoked by HMI to get list of registered apps. + DEPRECATED - This RPC is not implemented The name and ID of the device the list of registered applications is required for. -- cgit v1.2.1 From 9f18265c848f778ca580b02b9abebd96c09eaba9 Mon Sep 17 00:00:00 2001 From: "Yana Chernysheva (GitHub)" <59469418+ychernysheva@users.noreply.github.com> Date: Thu, 25 Jun 2020 17:57:22 +0300 Subject: Add check for already existed subscriptions during resumption in VehicleInfoPlugin (#3355) * Add check for already existed subscriptions --- .../vehicle_info_plugin/src/vehicle_info_plugin.cc | 40 +++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index 3e8ef6b29d..1c553fb84d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -154,28 +154,50 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() { application_manager_->GetRPCService().ManageHMICommand(message); } +bool IsOtherAppAlreadySubscribedFor( + const std::string& ivi_name, + const application_manager::ApplicationManager& app_mngr, + const uint32_t current_app_id) { + auto applications = app_mngr.applications(); + + for (auto& app : applications.GetData()) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + if (ext.isSubscribedToVehicleInfo(ivi_name) && + (app->app_id() != current_app_id)) { + return true; + } + } + return false; +} + void VehicleInfoPlugin::ProcessResumptionSubscription( application_manager::Application& app, VehicleInfoAppExtension& ext) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::app_id] = app.app_id(); + const auto& subscriptions = ext.Subscriptions(); + if (subscriptions.empty()) { LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting"); return; } - for (const auto& item : subscriptions) { - msg_params[item] = true; + for (auto& ivi : subscriptions) { + if (!IsOtherAppAlreadySubscribedFor( + ivi, *application_manager_, app.app_id())) { + msg_params[ivi] = true; + } } - smart_objects::SmartObjectSPtr request = - application_manager::MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, - *application_manager_); - (*request)[strings::msg_params] = msg_params; - application_manager_->GetRPCService().ManageHMICommand(request); + if (!msg_params.empty()) { + auto request = application_manager::MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, + *application_manager_); + msg_params[strings::app_id] = app.app_id(); + (*request)[strings::msg_params] = msg_params; + application_manager_->GetRPCService().ManageHMICommand(request); + } } application_manager::ApplicationSharedPtr FindAppSubscribedToIVI( -- cgit v1.2.1 From ab5604731c6445776081f8f9e053a031545f9167 Mon Sep 17 00:00:00 2001 From: Sho Amano Date: Tue, 30 Jun 2020 19:52:27 +0900 Subject: Fix/sdl 491 apt support formats (#2184) * Move definitions of SamplingRate / AudioCaptureQuality / AudioType to public header * Transfer AudioPassThru configuration to adapter * fix: apply AudioPassThru config to GStreamer pipeline * Update media manager test to remove deprecated method * Reflect code review comments - Update Doxygen comment format - Add description of create_caps_string() method * Fix style issue in from_mic_recorder_adapter.h * Update MediaManager to use Mobile API audio related enums Reflecting review comments. --- .../src/application_manager_impl.cc | 7 ++- .../test/application_manager_impl_test.cc | 22 +++++--- .../include/media_manager/media_manager.h | 16 ++++-- .../test/media_manager/mock_media_manager.h | 7 +++ .../audio/audio_stream_sender_thread.h | 16 ------ .../audio/from_mic_recorder_adapter.h | 10 +++- .../audio/from_mic_to_file_recorder_thread.h | 17 +++++- .../include/media_manager/media_manager_impl.h | 15 ++++-- .../src/audio/from_mic_recorder_adapter.cc | 21 +++++++- .../src/audio/from_mic_to_file_recorder_thread.cc | 63 ++++++++++++++++++++-- .../media_manager/src/media_manager_impl.cc | 18 ++++++- .../media_manager/test/media_manager_impl_test.cc | 21 ++++++-- 12 files changed, 192 insertions(+), 41 deletions(-) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 009052bc72..bd3f4b5f08 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1472,7 +1472,12 @@ void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key, LOG4CXX_INFO(logger_, "START MICROPHONE RECORDER"); DCHECK_OR_RETURN_VOID(media_manager_); media_manager_->StartMicrophoneRecording( - session_key, get_settings().recording_file_name(), max_duration); + session_key, + get_settings().recording_file_name(), + max_duration, + static_cast(sampling_rate), + static_cast(bits_per_sample), + static_cast(audio_type)); } void ApplicationManagerImpl::StopAudioPassThru(int32_t application_key) { diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 2c16048e97..687959263f 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -1198,14 +1198,19 @@ TEST_F(ApplicationManagerImplTest, StartStopAudioPassThru) { const uint32_t app_id = 65537; const int32_t max_duration = 1000; - // below are not used const int32_t correlation_id = 0; const int32_t sampling_rate = 0; const int32_t bits_per_sample = 0; const int32_t audio_type = 0; - EXPECT_CALL(mock_media_manager, - StartMicrophoneRecording(app_id, _, max_duration)) + EXPECT_CALL( + mock_media_manager, + StartMicrophoneRecording(app_id, + _, + max_duration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM)) .WillOnce(Return()); EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id)) .WillOnce(Return()); @@ -1282,14 +1287,19 @@ TEST_F(ApplicationManagerImplTest, UnregisterAnotherAppDuringAudioPassThru) { app_manager_impl_->AddMockApplication(mock_app_2); const int32_t max_duration = 1000; - // below are not used const int32_t correlation_id = 0; const int32_t sampling_rate = 0; const int32_t bits_per_sample = 0; const int32_t audio_type = 0; - EXPECT_CALL(mock_media_manager, - StartMicrophoneRecording(app_id_2, _, max_duration)) + EXPECT_CALL( + mock_media_manager, + StartMicrophoneRecording(app_id_2, + _, + max_duration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM)) .WillOnce(Return()); EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id_2)) .WillOnce(Return()); diff --git a/src/components/include/media_manager/media_manager.h b/src/components/include/media_manager/media_manager.h index 123e11f2f0..2d2201a949 100644 --- a/src/components/include/media_manager/media_manager.h +++ b/src/components/include/media_manager/media_manager.h @@ -34,8 +34,10 @@ #define SRC_COMPONENTS_INCLUDE_MEDIA_MANAGER_MEDIA_MANAGER_H_ #include +#include "interfaces/MOBILE_API.h" // see discussion in sdl_core PR #2184 #include "media_manager/media_manager_settings.h" #include "protocol/service_type.h" +#include "utils/macro.h" // for "DEPRECATED" namespace media_manager { class MediaManager { @@ -43,9 +45,17 @@ class MediaManager { virtual void PlayA2DPSource(int32_t application_key) = 0; virtual void StopA2DPSource(int32_t application_key) = 0; - virtual void StartMicrophoneRecording(int32_t application_key, - const std::string& outputFileName, - int32_t duration) = 0; + DEPRECATED virtual void StartMicrophoneRecording( + int32_t application_key, + const std::string& outputFileName, + int32_t duration) = 0; + virtual void StartMicrophoneRecording( + int32_t application_key, + const std::string& outputFileName, + int32_t duration, + mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type) = 0; virtual void StopMicrophoneRecording(int32_t application_key) = 0; virtual void StartStreaming(int32_t application_key, diff --git a/src/components/include/test/media_manager/mock_media_manager.h b/src/components/include/test/media_manager/mock_media_manager.h index aa0baa5682..364c495236 100644 --- a/src/components/include/test/media_manager/mock_media_manager.h +++ b/src/components/include/test/media_manager/mock_media_manager.h @@ -47,6 +47,13 @@ class MockMediaManager : public media_manager::MediaManager { void(int32_t application_key, const std::string& outputFileName, int32_t duration)); + MOCK_METHOD6(StartMicrophoneRecording, + void(int32_t application_key, + const std::string& outputFileName, + int32_t duration, + mobile_apis::SamplingRate::eType, + mobile_apis::BitsPerSample::eType, + mobile_apis::AudioType::eType)); MOCK_METHOD1(StopMicrophoneRecording, void(int32_t application_key)); MOCK_METHOD2(StartStreaming, void(int32_t application_key, diff --git a/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h b/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h index cb0ea8aa11..1999da987f 100644 --- a/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h +++ b/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h @@ -46,22 +46,6 @@ class ApplicationManager; namespace media_manager { -typedef enum { - SR_INVALID = -1, - SR_8KHZ = 0, - SR_16KHZ = 1, - SR_22KHZ = 2, - SR_44KHZ = 3 -} SamplingRate; - -typedef enum { - ACQ_INVALID = -1, - ACQ_8_BIT = 0, - ACQ_16_BIT = 1 -} AudioCaptureQuality; - -typedef enum { AT_INVALID = -1, AT_PCM = 0 } AudioType; - // AudioPassThru typedef struct { std::vector binary_data; diff --git a/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h b/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h index 7daf9c7add..9e0a8b5123 100644 --- a/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h +++ b/src/components/media_manager/include/media_manager/audio/from_mic_recorder_adapter.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_MEDIA_MANAGER_INCLUDE_MEDIA_MANAGER_AUDIO_FROM_MIC_RECORDER_ADAPTER_H_ #include +#include "interfaces/MOBILE_API.h" #include "media_manager/media_adapter_impl.h" namespace threads { @@ -52,12 +53,19 @@ class FromMicRecorderAdapter : public MediaAdapterImpl { void StopActivity(int32_t application_key); bool is_app_performing_activity(int32_t application_key) const; void set_output_file(const std::string& output_file); - void set_duration(int32_t duration); + DEPRECATED void set_duration(int32_t duration); + void set_config(mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type, + int32_t duration); private: threads::Thread* recorder_thread_; std::string output_file_; const int32_t kDefaultDuration; + mobile_apis::SamplingRate::eType sampling_rate_; + mobile_apis::BitsPerSample::eType bits_per_sample_; + mobile_apis::AudioType::eType audio_type_; int32_t duration_; DISALLOW_COPY_AND_ASSIGN(FromMicRecorderAdapter); }; diff --git a/src/components/media_manager/include/media_manager/audio/from_mic_to_file_recorder_thread.h b/src/components/media_manager/include/media_manager/audio/from_mic_to_file_recorder_thread.h index e6b54cc487..89c298f280 100644 --- a/src/components/media_manager/include/media_manager/audio/from_mic_to_file_recorder_thread.h +++ b/src/components/media_manager/include/media_manager/audio/from_mic_to_file_recorder_thread.h @@ -37,6 +37,7 @@ #include #include +#include "interfaces/MOBILE_API.h" #include "utils/lock.h" #include "utils/threads/thread.h" #include "utils/threads/thread_delegate.h" @@ -45,7 +46,15 @@ namespace media_manager { class FromMicToFileRecorderThread : public threads::ThreadDelegate { public: - FromMicToFileRecorderThread(const std::string& output_file, int32_t duration); + FromMicToFileRecorderThread( + const std::string& output_file, + int32_t duration, + mobile_apis::SamplingRate::eType sampling_rate = + mobile_apis::SamplingRate::INVALID_ENUM, + mobile_apis::BitsPerSample::eType bits_per_sample = + mobile_apis::BitsPerSample::INVALID_ENUM, + mobile_apis::AudioType::eType audio_type = + mobile_apis::AudioType::INVALID_ENUM); ~FromMicToFileRecorderThread(); void threadMain(); @@ -67,6 +76,8 @@ class FromMicToFileRecorderThread : public threads::ThreadDelegate { sync_primitives::Lock stopFlagLock_; std::string outputFileName_, durationString_; + mobile_apis::SamplingRate::eType samplingRate_; + mobile_apis::BitsPerSample::eType bitsPerSample_; typedef struct { GstElement* pipeline; @@ -77,6 +88,10 @@ class FromMicToFileRecorderThread : public threads::ThreadDelegate { void deinitArgs(); void psleep(void* timeout); + // create_caps_string() creates a string which is fed to capsfilter's "caps" + // property. The string specifies audio format. example: + // "audio/x-raw,format=(string)S16LE,rate=44100,channels=1" + std::string create_caps_string(); class SleepThreadDelegate : public threads::ThreadDelegate { public: diff --git a/src/components/media_manager/include/media_manager/media_manager_impl.h b/src/components/media_manager/include/media_manager/media_manager_impl.h index 408fa12655..3e24212ed5 100644 --- a/src/components/media_manager/include/media_manager/media_manager_impl.h +++ b/src/components/media_manager/include/media_manager/media_manager_impl.h @@ -36,6 +36,7 @@ #include #include #include +#include "interfaces/MOBILE_API.h" #include "media_manager/media_adapter_impl.h" #include "media_manager/media_adapter_listener.h" #include "media_manager/media_manager.h" @@ -62,9 +63,17 @@ class MediaManagerImpl : public MediaManager, virtual void PlayA2DPSource(int32_t application_key); virtual void StopA2DPSource(int32_t application_key); - virtual void StartMicrophoneRecording(int32_t application_key, - const std::string& outputFileName, - int32_t duration); + DEPRECATED virtual void StartMicrophoneRecording( + int32_t application_key, + const std::string& outputFileName, + int32_t duration); + virtual void StartMicrophoneRecording( + int32_t application_key, + const std::string& outputFileName, + int32_t duration, + mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type); virtual void StopMicrophoneRecording(int32_t application_key); virtual void StartStreaming(int32_t application_key, diff --git a/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc b/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc index e55efed4ce..2575643422 100644 --- a/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc +++ b/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc @@ -32,6 +32,7 @@ #include "media_manager/audio/from_mic_recorder_adapter.h" #include +#include "interfaces/MOBILE_API.h" #include "media_manager/audio/from_mic_to_file_recorder_thread.h" #include "utils/logger.h" #include "utils/threads/thread.h" @@ -44,6 +45,9 @@ FromMicRecorderAdapter::FromMicRecorderAdapter() : recorder_thread_(NULL) , output_file_("default_recorded_audio.wav") , kDefaultDuration(1000) + , sampling_rate_(mobile_apis::SamplingRate::INVALID_ENUM) + , bits_per_sample_(mobile_apis::BitsPerSample::INVALID_ENUM) + , audio_type_(mobile_apis::AudioType::INVALID_ENUM) , duration_(kDefaultDuration) {} FromMicRecorderAdapter::~FromMicRecorderAdapter() { @@ -66,7 +70,11 @@ void FromMicRecorderAdapter::StartActivity(int32_t application_key) { // Todd: No gstreamer recorder thread if (!recorder_thread_) { FromMicToFileRecorderThread* thread_delegate = - new FromMicToFileRecorderThread(output_file_, duration_); + new FromMicToFileRecorderThread(output_file_, + duration_, + sampling_rate_, + bits_per_sample_, + audio_type_); recorder_thread_ = threads::CreateThread("MicrophoneRec", thread_delegate); } @@ -107,4 +115,15 @@ void FromMicRecorderAdapter::set_duration(int32_t duration) { duration_ = duration; } +void FromMicRecorderAdapter::set_config( + mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type, + int32_t duration) { + sampling_rate_ = sampling_rate; + bits_per_sample_ = bits_per_sample; + audio_type_ = audio_type; + duration_ = duration; +} + } // namespace media_manager diff --git a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc index a34bdd3f09..877722fd70 100644 --- a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc +++ b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc @@ -34,6 +34,7 @@ #include #include #include +#include "interfaces/MOBILE_API.h" #include "utils/logger.h" namespace media_manager { @@ -46,16 +47,23 @@ GMainLoop* FromMicToFileRecorderThread::loop = NULL; static const int kNumAudioChannels = 1; FromMicToFileRecorderThread::FromMicToFileRecorderThread( - const std::string& output_file, int32_t duration) + const std::string& output_file, + int32_t duration, + mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type) : threads::ThreadDelegate() , argc_(5) , argv_(NULL) , oKey_("-o") , tKey_("-t") , sleepThread_(NULL) - , outputFileName_(output_file) { + , outputFileName_(output_file) + , samplingRate_(sampling_rate) + , bitsPerSample_(bits_per_sample) { LOG4CXX_AUTO_TRACE(logger_); set_record_duration(duration); + // audio_type is not used as we always employ LPCM } FromMicToFileRecorderThread::~FromMicToFileRecorderThread() { @@ -205,9 +213,11 @@ void FromMicToFileRecorderThread::threadMain() { wavenc = gst_element_factory_make("wavenc", "wavenc0"); filesink = gst_element_factory_make("filesink", "filesink0"); - // create a capability to downmix the recorded audio to monaural - audiocaps = gst_caps_new_simple( - "audio/x-raw", "channels", G_TYPE_INT, kNumAudioChannels, NULL); + // Create a capability to specify audio format. It also downmixes the recorded + // audio to monaural. + std::string caps_string = create_caps_string(); + LOG4CXX_DEBUG(logger_, "Using audio caps: " << caps_string); + audiocaps = gst_caps_from_string(caps_string.c_str()); // Assert that all the elements were created if (!alsasrc || !audioconvert || !capsfilter || !wavenc || !filesink || @@ -285,6 +295,49 @@ void FromMicToFileRecorderThread::threadMain() { loop = NULL; } +std::string FromMicToFileRecorderThread::create_caps_string() { + LOG4CXX_AUTO_TRACE(logger_); + + std::stringstream ss; + ss << "audio/x-raw"; + + switch (bitsPerSample_) { + case mobile_apis::BitsPerSample::BitsPerSample_8_BIT: + // format is 8-bit unsigned + ss << ",format=(string)U8"; + break; + case mobile_apis::BitsPerSample::BitsPerSample_16_BIT: + // format is 16-bit signed, in little endian + ss << ",format=(string)S16LE"; + break; + default: + // do not specify the format; use system default + break; + } + + switch (samplingRate_) { + case mobile_apis::SamplingRate::SamplingRate_8KHZ: + ss << ",rate=8000"; + break; + case mobile_apis::SamplingRate::SamplingRate_16KHZ: + ss << ",rate=16000"; + break; + case mobile_apis::SamplingRate::SamplingRate_22KHZ: + ss << ",rate=22050"; + break; + case mobile_apis::SamplingRate::SamplingRate_44KHZ: + ss << ",rate=44100"; + break; + default: + // do not specify the sampling rate; use system default + break; + } + + ss << ",channels=" << kNumAudioChannels; + + return ss.str(); +} + FromMicToFileRecorderThread::SleepThreadDelegate::SleepThreadDelegate( GstTimeout timeout) : threads::ThreadDelegate(), timeout_(timeout) {} diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc index b04381605d..d7352d0025 100644 --- a/src/components/media_manager/src/media_manager_impl.cc +++ b/src/components/media_manager/src/media_manager_impl.cc @@ -36,6 +36,7 @@ #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" #include "application_manager/smart_object_keys.h" +#include "interfaces/MOBILE_API.h" #include "media_manager/audio/from_mic_recorder_listener.h" #include "media_manager/streamer_listener.h" #include "protocol_handler/protocol_handler.h" @@ -208,6 +209,21 @@ void MediaManagerImpl::StopA2DPSource(int32_t application_key) { void MediaManagerImpl::StartMicrophoneRecording(int32_t application_key, const std::string& output_file, int32_t duration) { + StartMicrophoneRecording(application_key, + output_file, + duration, + mobile_apis::SamplingRate::INVALID_ENUM, + mobile_apis::BitsPerSample::INVALID_ENUM, + mobile_apis::AudioType::INVALID_ENUM); +} + +void MediaManagerImpl::StartMicrophoneRecording( + int32_t application_key, + const std::string& output_file, + int32_t duration, + mobile_apis::SamplingRate::eType sampling_rate, + mobile_apis::BitsPerSample::eType bits_per_sample, + mobile_apis::AudioType::eType audio_type) { LOG4CXX_INFO(logger_, "MediaManagerImpl::StartMicrophoneRecording to " << output_file); application_manager::ApplicationSharedPtr app = @@ -223,7 +239,7 @@ void MediaManagerImpl::StartMicrophoneRecording(int32_t application_key, (static_cast(from_mic_recorder_)) ->set_output_file(file_path); (static_cast(from_mic_recorder_)) - ->set_duration(duration); + ->set_config(sampling_rate, bits_per_sample, audio_type, duration); from_mic_recorder_->StartActivity(application_key); } #else diff --git a/src/components/media_manager/test/media_manager_impl_test.cc b/src/components/media_manager/test/media_manager_impl_test.cc index 627e2f57ed..3b4e6f6150 100644 --- a/src/components/media_manager/test/media_manager_impl_test.cc +++ b/src/components/media_manager/test/media_manager_impl_test.cc @@ -331,7 +331,12 @@ TEST_F(MediaManagerImplTest, EXPECT_EQ(data[i], result[i]); } media_manager_impl_->StartMicrophoneRecording( - kApplicationKey, kOutputFile, kDuration); + kApplicationKey, + kOutputFile, + kDuration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM); EXPECT_TRUE(RemoveDirectory(kResourceFolder, true)); EXPECT_TRUE(RemoveDirectory(kStorageFolder, true)); } @@ -342,7 +347,12 @@ TEST_F(MediaManagerImplTest, media_manager_impl_->set_mock_mic_listener(media_adapter_listener_mock_); EXPECT_FALSE(FileExists(kOutputFilePath)); media_manager_impl_->StartMicrophoneRecording( - kApplicationKey, kOutputFile, kDuration); + kApplicationKey, + kOutputFile, + kDuration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM); } TEST_F(MediaManagerImplTest, @@ -358,7 +368,12 @@ TEST_F(MediaManagerImplTest, media_manager_impl_->set_mock_mic_listener(media_adapter_listener_mock_); EXPECT_TRUE(FileExists(kOutputFilePath)); media_manager_impl_->StartMicrophoneRecording( - kApplicationKey, kOutputFile, kDuration); + kApplicationKey, + kOutputFile, + kDuration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM); chmod(kOutputFilePath.c_str(), S_IWUSR); EXPECT_TRUE(RemoveDirectory(kStorageFolder, true)); } -- cgit v1.2.1 From 0330f350872671f59e66394a54416cf654c72dbb Mon Sep 17 00:00:00 2001 From: Jim-Nexty <35795928+zhouxin627@users.noreply.github.com> Date: Wed, 1 Jul 2020 02:56:14 +0900 Subject: Fix 3119 bug:App gets REJECTED instead of UNSUPPORTED_RESOURCE to ChangeRegistration with not supported language (#3427) Co-authored-by: zhangwenqin --- .../sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc index 50217a9c8a..19584fb055 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc @@ -177,7 +177,7 @@ void ChangeRegistrationRequest::Run() { IsLanguageSupportedByVR(language) && IsLanguageSupportedByTTS(language))) { LOG4CXX_ERROR(logger_, "Language is not supported"); - SendResponse(false, mobile_apis::Result::REJECTED); + SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); return; } -- cgit v1.2.1 From 648a510c0ab4e1bf0a410e28b6e4440a12842ec6 Mon Sep 17 00:00:00 2001 From: "Igor Gapchuk (GitHub)" <41586842+IGapchuk@users.noreply.github.com> Date: Tue, 7 Jul 2020 17:51:15 +0300 Subject: Feature/aligning hmi mobile api for pcm stream capabilities (#3297) * Adding pcmStreamCapabilities param to HMI API in UI.GetCapabilities * Adding to read pcmStreamCapabilities from HMI * Add unit test to cover a test case Co-authored-by: sniukalov --- .../src/commands/hmi/ui_get_capabilities_response.cc | 5 +++++ .../commands/hmi/ui_get_capabilities_response_test.cc | 18 ++++++++++++++++++ src/components/interfaces/HMI_API.xml | 1 + 3 files changed, 24 insertions(+) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc index a3eb9244bd..45ae49f205 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc @@ -128,6 +128,11 @@ void UIGetCapabilitiesResponse::Run() { [strings::display_capabilities]); } } + + if (msg_params.keyExists(strings::pcm_stream_capabilities)) { + hmi_capabilities.set_pcm_stream_capabilities( + msg_params[strings::pcm_stream_capabilities]); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc index 4683fc62c7..e6db817fed 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -362,6 +362,24 @@ TEST_F(UIGetCapabilitiesResponseTest, SetSystemDisplayCapabilities_SUCCESS) { command->Run(); } +TEST_F(UIGetCapabilitiesResponseTest, SetPCMStreamCapabilities_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::pcm_stream_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + const auto& pcm_capabilities_so = + (*command_msg)[strings::msg_params][strings::pcm_stream_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_pcm_stream_capabilities(pcm_capabilities_so)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + } // namespace ui_get_capabilities_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 7fd1b8fd1b..0b189c4bca 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -5444,6 +5444,7 @@ Specifies system capabilities. See SystemCapabilities + Request from SmartDeviceLink to HMI to change language for app. -- cgit v1.2.1 From 81fb32e394ead932632bf2ee175f561027afbe2b Mon Sep 17 00:00:00 2001 From: "Alexander Kutsan (GitHub)" Date: Mon, 13 Jul 2020 17:19:53 +0300 Subject: SDLCORE-459:Make refactoring in mb_controller.cc (#3381) SDLCORE-459 Fix race condition ragarding Helgrind issue. Error 9 : Possible race condition in case of using assignment operator with atomic variable 'shutdown_', fix via using 'atomic_exchange'. Error 10: Incorrect sequence of closing boost asio objects. Add member function into CMessageBrokerController for correct close sequence. Co-authored-by: Maksym Shvaiko --- .../include/hmi_message_handler/mb_controller.h | 4 +- .../hmi_message_handler/src/mb_controller.cc | 64 ++++++++++++---------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/mb_controller.h b/src/components/hmi_message_handler/include/hmi_message_handler/mb_controller.h index 544a3ca275..b4c03fd760 100644 --- a/src/components/hmi_message_handler/include/hmi_message_handler/mb_controller.h +++ b/src/components/hmi_message_handler/include/hmi_message_handler/mb_controller.h @@ -149,6 +149,8 @@ class CMessageBrokerController int getNextControllerId(); private: + void CloseConnection(); + boost::asio::io_context ioc_; const std::string& address_; uint16_t port_; @@ -182,4 +184,4 @@ class CMessageBrokerController } // namespace hmi_message_handler -#endif /* MB_CONTROLLER_H */ \ No newline at end of file +#endif /* MB_CONTROLLER_H */ diff --git a/src/components/hmi_message_handler/src/mb_controller.cc b/src/components/hmi_message_handler/src/mb_controller.cc index ffc6ef23a3..cfc05647da 100644 --- a/src/components/hmi_message_handler/src/mb_controller.cc +++ b/src/components/hmi_message_handler/src/mb_controller.cc @@ -50,15 +50,8 @@ CMessageBrokerController::CMessageBrokerController(const std::string& address, } CMessageBrokerController::~CMessageBrokerController() { - boost::system::error_code ec; - socket_.close(); - acceptor_.close(ec); - if (ec) { - std::string str_err = "ErrorMessage Close: " + ec.message(); - LOG4CXX_ERROR(mb_logger_, str_err); - } - shutdown_ = true; - ioc_.stop(); + shutdown_.exchange(true); + CloseConnection(); } bool CMessageBrokerController::StartListener() { @@ -114,9 +107,8 @@ void CMessageBrokerController::WaitForConnection() { void CMessageBrokerController::StartSession(boost::system::error_code ec) { if (ec) { - std::string str_err = "ErrorMessage: " + ec.message(); - LOG4CXX_ERROR(mb_logger_, str_err); - ioc_.stop(); + LOG4CXX_ERROR(mb_logger_, "ErrorMessage: " << ec.message()); + CloseConnection(); return; } if (shutdown_) { @@ -147,7 +139,7 @@ void CMessageBrokerController::sendNotification(Json::Value& message) { int subscribersCount = getSubscribersFd(methodName, result); if (0 < subscribersCount) { std::vector::iterator it; - for (it = result.begin(); it != result.end(); it++) { + for (it = result.begin(); it != result.end(); ++it) { (*it)->sendJsonMessage(message); } } else { @@ -216,7 +208,8 @@ bool CMessageBrokerController::Connect() { } void CMessageBrokerController::exitReceivingThread() { - shutdown_ = true; + shutdown_.exchange(true); + mConnectionListLock.Acquire(); std::vector >::iterator it; @@ -225,19 +218,7 @@ void CMessageBrokerController::exitReceivingThread() { it = mConnectionList.erase(it); } mConnectionListLock.Release(); - - boost::system::error_code ec; - socket_.close(); - acceptor_.cancel(ec); - if (ec) { - std::string str_err = "ErrorMessage Cancel: " + ec.message(); - LOG4CXX_ERROR(mb_logger_, str_err); - } - acceptor_.close(ec); - if (ec) { - std::string str_err = "ErrorMessage Close: " + ec.message(); - } - ioc_.stop(); + CloseConnection(); } std::string CMessageBrokerController::getMethodName(std::string& method) { @@ -287,7 +268,7 @@ void CMessageBrokerController::deleteController(WebsocketSession* ws_session) { if (it->second == ws_session) { mControllersList.erase(it++); } else { - it++; + ++it; } } } @@ -341,7 +322,7 @@ bool CMessageBrokerController::addSubscriber(WebsocketSession* ws_session, p = mSubscribersList.equal_range(name); if (p.first != p.second) { std::multimap::iterator itr; - for (itr = p.first; itr != p.second; itr++) { + for (itr = p.first; itr != p.second; ++itr) { if (ws_session == itr->second) { result = false; LOG4CXX_ERROR(mb_logger_, ("Subscriber already exists!\n")); @@ -384,7 +365,7 @@ int CMessageBrokerController::getSubscribersFd( p = mSubscribersList.equal_range(name); if (p.first != p.second) { std::multimap::iterator itr; - for (itr = p.first; itr != p.second; itr++) { + for (itr = p.first; itr != p.second; ++itr) { result.push_back(itr->second); } } @@ -501,4 +482,27 @@ void CMessageBrokerController::processInternalRequest( int CMessageBrokerController::getNextControllerId() { return 1000 * mControllersIdCounter++; } + +void CMessageBrokerController::CloseConnection() { + if (!ioc_.stopped()) { + boost::system::error_code ec; + + acceptor_.cancel(ec); + if (ec) { + LOG4CXX_ERROR(mb_logger_, "Acceptor cancel error: " << ec.message()); + } + + acceptor_.close(ec); + if (ec) { + LOG4CXX_ERROR(mb_logger_, "Acceptor close error: " << ec.message()); + } + + socket_.close(ec); + if (ec) { + LOG4CXX_ERROR(mb_logger_, "Socket close error : " << ec.message()); + } + + ioc_.stop(); + } +} } // namespace hmi_message_handler -- cgit v1.2.1 From 5e2dff6d31554d5bd4534ec7f7702dc2f877340e Mon Sep 17 00:00:00 2001 From: Yevhenii Dementieiev <57259850+ydementieiev@users.noreply.github.com> Date: Fri, 17 Jul 2020 18:48:45 +0300 Subject: [SDL 0249] Feature/persisting hmi capabilities (#3397) * Replace raw pointers with shared pointers * Save UI.GetCapabilities, UI.GetLanguage, UI.GetSupportedLanguages responses into the file specified by ini file If ini file contains an empty path to the cache file, this feature will be disabled and SDL will work as before. SDL will save each response only first time, after that file will not be overwritten. On master reset SDL will remove the cache file. SDL will read default hmi capability values from the cache file on each system boot up * Fix doxygen * Define HMI interfaces aliases * Implement caching for VR, TTS, Buttons, VehicheInfo and RC capabilities * Fix default capabilities structure according to the HMI API * Send requests to get capabilities from HMI in case any capability is missing in cache * Refactor RC capabilities storing and retrieving. Fix related UTs. * Created implementation and unit tests for HMI capabilities persistence after SW update * Created implementation for save and received MetaInfo * Increase unit tests coverage on persistence HMI capabilities * Do not rewrite MetaInfo in case invalid BC.GetSystemInfo response from HMI * Read pcm_stream_capabilities from HMI and save to the cache * Refactor hmi capabilities test * Fix wrong convert PrerecordedSpeech and added unit test for check * Suspend response to RAI requests until HMI has responded to all the HMI capabilities * Request appropriate capabilities if they are not present in the cache and the default capabilities as well * fixup! Send requests to get capabilities from HMI in case any capability is missing in cache * Remove hm_capabilities.json test file It should be removed because during UT building the real hmi_capabilities.json file is copying to the test directory * Re-factor HMICapabilitiesImpl and add the new one method Make changes in the next places: - GetRequestsRequiredForCapabilities method rename to IsRequestsRequiredForCapabilities and return value change to bool. This commit provides the next implementation: the method checks if specified request should be sent to the HMI; - in the save_hmi_capability_field_to_json method remove redundant section in the json node to save; - JsonCapabilitiesGetter: GetInterfaceJsonMember method rename to IsInterfaceJsonMemberExists. Return value change to bool; - Add the new one function GetInterfaceGetter: returns the JsonCapabilitiesGetter according to specified interface name; - Parsing the capabilities cache file wrapped to the try/catch construction; - Add AddRequiredRequestsForCapabilities method; - Remove MatchesCCPUVersion method as redundant; - Rework PrepareXXXJsonValueForSaving methods; - Add new Unit tests for HMICapabilitiesImpl; - Update existing Unit tests according to the appropriate changes; * Update CCPU Version max value parameter (regular and external policies) * Minor updates: - Remove input parameter for the GetSystemInfo method, move the OnSoftwareVersionReceived method out of GetSystemInfo method; - UIGetCapabilitiesResponse: retrieve reference for a specific section from a message instead of using the whole path to needed section; - OnTTSLanguageChangeNotification: add saving cached capabilities for VR; - OnVRLanguageChangeNotification: update log info; - VRGetCapabilitiesResponse: retrieve reference for a specific section from a message instead of using the whole path to needed section; - VRGetSupportedLanguagesResponse: update log info; - CacheManager (regular and external policies): add doxygen description for the SetPreloadedPtFlag method; move back meta info out of "for" loop; * Minor changes for the Unit tests * Fix SDL Core crash during getting RC capability There the case when RC capability didn't initialized yet and rc_capability() method is calling and returns invalid pointer to the RC capability. This commit provides the next changes: - Add check for returned pointer to rc_capability; - Add the new one capabilitiesStatus parameter "kInvalidStatus" for return value for the GetModuleDataCapabilities method; - Update capabilitiesStatus parameter names according to the coding style; * fixup! Re-factor HMICapabilitiesImpl and add the new one method * fixup! Re-factor HMICapabilitiesImpl and add the new one method * fixup! Re-factor HMICapabilitiesImpl and add the new one method * Remove "system_display_capabilities" smart key * Add to the RequestToHMI the RequestCapabilities method The "RequestCapabilities" methos is common for the all *IsReady requests. Because of that it was moved to the base class with common logic. * Re-factor all *IsReady request. The logic for getting capabilities from HMI is common for the all *IsReady request. This logic is implemented in the base RequestToHMI class. So, this logic should be removed from each request and the method of the base class should be used. * fixup! Re-factor all *IsReady request. Co-authored-by: LitvinenkoIra Co-authored-by: Igor Gapchuk Co-authored-by: Yevhenii Dementieiev (GitHub) Co-authored-by: sniukalov --- src/appMain/hmi_capabilities.json | 1121 +++++++------- src/appMain/smartDeviceLink.ini | 2 + .../application_manager/application_manager_impl.h | 6 +- .../application_manager/commands/request_to_hmi.h | 31 + .../application_manager/hmi_capabilities_impl.h | 514 +++--- .../application_manager/policies/policy_handler.h | 4 + .../application_manager/smart_object_keys.h | 14 + .../rc_rpc_plugin/rc_capabilities_manager.h | 8 +- .../include/rc_rpc_plugin/rc_module_constants.h | 11 +- .../mobile/get_interior_vehicle_data_request.cc | 5 +- ...release_interior_vehicle_data_module_request.cc | 5 +- .../mobile/set_interior_vehicle_data_request.cc | 16 +- .../src/commands/rc_command_request.cc | 4 +- .../src/rc_capabilities_manager_impl.cc | 102 +- .../test/commands/button_press_request_test.cc | 9 +- .../get_interior_vehicle_data_request_test.cc | 9 +- .../rc_get_interior_vehicle_data_consent_test.cc | 9 +- ...se_interior_vehicle_data_module_request_test.cc | 42 +- .../set_interior_vehicle_data_request_test.cc | 12 +- .../commands/hmi/button_get_capabilities_request.h | 7 +- .../commands/hmi/get_system_info_request.h | 7 +- .../commands/hmi/get_system_info_response.h | 3 +- .../commands/hmi/rc_get_capabilities_request.h | 7 +- .../commands/hmi/rc_is_ready_request.h | 6 - .../commands/hmi/tts_get_capabilities_request.h | 7 +- .../commands/hmi/tts_get_language_request.h | 7 +- .../hmi/tts_get_supported_languages_request.h | 7 +- .../commands/hmi/tts_is_ready_request.h | 7 +- .../commands/hmi/ui_get_capabilities_request.h | 7 +- .../commands/hmi/ui_get_language_request.h | 7 +- .../hmi/ui_get_supported_languages_request.h | 7 +- .../commands/hmi/ui_is_ready_request.h | 7 +- .../commands/hmi/vr_get_capabilities_request.h | 7 +- .../commands/hmi/vr_get_language_request.h | 7 +- .../hmi/vr_get_supported_languages_request.h | 7 +- .../commands/hmi/vr_is_ready_request.h | 8 +- .../hmi/button_get_capabilities_request.cc | 6 + .../hmi/button_get_capabilities_response.cc | 18 +- .../src/commands/hmi/get_system_info_request.cc | 5 + .../src/commands/hmi/get_system_info_response.cc | 36 +- .../src/commands/hmi/on_ready_notification.cc | 2 +- .../hmi/on_tts_language_change_notification.cc | 21 +- .../hmi/on_ui_language_change_notification.cc | 13 +- .../hmi/on_vr_language_change_notification.cc | 13 +- .../commands/hmi/rc_get_capabilities_request.cc | 6 + .../commands/hmi/rc_get_capabilities_response.cc | 28 +- .../src/commands/hmi/rc_is_ready_request.cc | 16 +- .../commands/hmi/tts_get_capabilities_request.cc | 5 + .../commands/hmi/tts_get_capabilities_response.cc | 25 +- .../src/commands/hmi/tts_get_language_request.cc | 5 + .../src/commands/hmi/tts_get_language_response.cc | 18 + .../hmi/tts_get_supported_languages_request.cc | 5 + .../hmi/tts_get_supported_languages_response.cc | 20 +- .../src/commands/hmi/tts_is_ready_request.cc | 25 +- .../commands/hmi/ui_get_capabilities_request.cc | 5 + .../commands/hmi/ui_get_capabilities_response.cc | 84 +- .../src/commands/hmi/ui_get_language_request.cc | 5 + .../src/commands/hmi/ui_get_language_response.cc | 17 + .../hmi/ui_get_supported_languages_request.cc | 5 + .../hmi/ui_get_supported_languages_response.cc | 20 +- .../src/commands/hmi/ui_is_ready_request.cc | 25 +- .../commands/hmi/vr_get_capabilities_request.cc | 5 + .../commands/hmi/vr_get_capabilities_response.cc | 27 +- .../src/commands/hmi/vr_get_language_request.cc | 5 + .../src/commands/hmi/vr_get_language_response.cc | 17 + .../hmi/vr_get_supported_languages_request.cc | 5 + .../hmi/vr_get_supported_languages_response.cc | 10 + .../src/commands/hmi/vr_is_ready_request.cc | 24 +- .../commands/mobile/change_registration_request.cc | 9 +- .../hmi/button_get_capabilities_request_test.cc | 116 ++ .../hmi/button_get_capabilities_response_test.cc | 18 + .../commands/hmi/get_system_info_response_test.cc | 18 +- .../test/commands/hmi/hmi_notifications_test.cc | 2 +- .../hmi/rc_get_capabilities_request_test.cc | 106 ++ .../hmi/rc_get_capabilities_response_test.cc | 18 + .../test/commands/hmi/rc_is_ready_request_test.cc | 11 +- .../hmi/tts_get_capabilities_request_test.cc | 117 ++ .../hmi/tts_get_capabilities_response_test.cc | 40 +- .../commands/hmi/tts_get_language_request_test.cc | 115 ++ .../commands/hmi/tts_get_language_response_test.cc | 30 + .../tts_get_supported_languages_request_test.cc | 118 ++ .../tts_get_supported_languages_response_test.cc | 22 + .../test/commands/hmi/tts_is_ready_request_test.cc | 252 +++ .../hmi/ui_get_capabilities_request_test.cc | 115 ++ .../hmi/ui_get_capabilities_response_test.cc | 39 +- .../commands/hmi/ui_get_language_request_test.cc | 115 ++ .../commands/hmi/ui_get_language_response_test.cc | 28 + .../hmi/ui_get_supported_languages_request_test.cc | 118 ++ .../ui_get_supported_languages_response_test.cc | 22 + .../test/commands/hmi/ui_is_ready_request_test.cc | 27 +- .../test/commands/hmi/update_sdl_request_test.cc | 2 +- .../test/commands/hmi/update_sdl_response_test.cc | 2 +- .../hmi/vr_get_capabilities_request_test.cc | 115 ++ .../hmi/vr_get_capabilities_response_test.cc | 21 + .../commands/hmi/vr_get_language_request_test.cc | 115 ++ .../commands/hmi/vr_get_language_response_test.cc | 30 + .../hmi/vr_get_supported_languages_request_test.cc | 118 ++ .../vr_get_supported_languages_response_test.cc | 22 + .../test/commands/hmi/vr_is_ready_request_test.cc | 38 +- .../commands/mobile/change_registration_test.cc | 18 +- .../mobile/register_app_interface_request_test.cc | 2 + .../commands/hmi/vi_get_vehicle_type_request.h | 7 +- .../commands/hmi/vi_is_ready_request.h | 5 - .../commands/hmi/vi_get_vehicle_type_request.cc | 6 + .../commands/hmi/vi_get_vehicle_type_response.cc | 23 +- .../src/commands/hmi/vi_is_ready_request.cc | 18 +- .../hmi/vi_get_vehicle_data_response_test.cc | 2 +- .../hmi/vi_get_vehicle_type_request_test.cc | 109 ++ .../hmi/vi_get_vehicle_type_response_test.cc | 142 ++ .../test/commands/hmi/vi_is_ready_request_test.cc | 105 +- .../src/application_manager_impl.cc | 72 +- .../src/commands/command_request_impl.cc | 20 +- .../src/commands/request_to_hmi.cc | 84 + .../src/hmi_capabilities_impl.cc | 1278 ++++++++++++--- .../src/policies/policy_handler.cc | 10 + .../application_manager/src/smart_object_keys.cc | 14 + .../application_manager/test/CMakeLists.txt | 3 +- .../test/application_manager_impl_test.cc | 38 + .../application_manager/test/hmi_capabilities.json | 731 --------- .../test/hmi_capabilities_sc2.json | 6 + .../test/hmi_capabilities_test.cc | 1629 ++++++++++++++++---- .../hmi_capabilities_for_testing.h | 56 - .../application_manager/mock_hmi_capabilities.h | 40 +- .../include/config_profile/profile.h | 7 + src/components/config_profile/src/profile.cc | 21 + .../application_manager/application_manager.h | 15 +- .../application_manager_settings.h | 1 + .../include/application_manager/hmi_capabilities.h | 274 ++-- .../policies/policy_handler_interface.h | 12 + .../policy/policy_external/policy/policy_manager.h | 12 + .../policy/policy_regular/policy/policy_manager.h | 12 + .../application_manager/mock_application_manager.h | 4 +- .../mock_application_manager_settings.h | 1 + .../policies/mock_policy_handler_interface.h | 2 + .../policy_external/policy/mock_cache_manager.h | 2 + .../policy_external/policy/mock_policy_manager.h | 2 + .../policy_regular/policy/mock_cache_manager.h | 2 + .../policy_regular/policy/mock_policy_manager.h | 2 + .../policy_external/include/policy/cache_manager.h | 12 + .../include/policy/cache_manager_interface.h | 12 + .../include/policy/policy_manager_impl.h | 4 + .../include/policy/policy_table/types.h | 2 +- .../policy/policy_external/src/cache_manager.cc | 13 + .../policy_external/src/policy_manager_impl.cc | 10 + .../policy_regular/include/policy/cache_manager.h | 12 + .../include/policy/cache_manager_interface.h | 12 + .../include/policy/policy_manager_impl.h | 4 + .../include/policy/policy_table/types.h | 1 + .../include/policy/pt_representation.h | 6 + .../policy_regular/include/policy/sql_pt_queries.h | 1 + .../include/policy/sql_pt_representation.h | 2 +- .../policy/policy_regular/src/cache_manager.cc | 22 +- .../policy_regular/src/policy_manager_impl.cc | 11 + .../policy_regular/src/policy_table/types.cc | 12 +- .../policy/policy_regular/src/sql_pt_queries.cc | 7 +- .../policy_regular/src/sql_pt_representation.cc | 18 + .../test/policy_manager_impl_test.cc | 142 +- 157 files changed, 6657 insertions(+), 2912 deletions(-) create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc delete mode 100644 src/components/application_manager/test/hmi_capabilities.json delete mode 100644 src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h diff --git a/src/appMain/hmi_capabilities.json b/src/appMain/hmi_capabilities.json index 91ddaf6d6c..29604f0c2c 100755 --- a/src/appMain/hmi_capabilities.json +++ b/src/appMain/hmi_capabilities.json @@ -324,612 +324,614 @@ "diagonalScreenSize": 8, "pixelPerInch": 117, "scale": 1 - }, - "seatLocationCapability": { - "rows": 2, - "columns": 3, - "levels": 1, - "seats": [ - { - "row": 0, - "col": 0, - "level": 0, - "rowspan": 1, - "levelspan": 1, - "colspan": 1 - } - ] - }, - "remoteControlCapability": { - "buttonCapabilities": [ - { - "longPressAvailable": true, - "name": "AC_MAX", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + } + } + }, + "RC" : { + "remoteControlCapability" : { + "buttonCapabilities": [ + { + "longPressAvailable": true, + "name": "AC_MAX", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "AC", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "AC", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "RECIRCULATE", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "RECIRCULATE", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "FAN_UP", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "FAN_UP", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "FAN_DOWN", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "FAN_DOWN", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "TEMP_UP", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "TEMP_UP", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "TEMP_DOWN", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "TEMP_DOWN", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "DEFROST_MAX", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "DEFROST_MAX", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "DEFROST", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "DEFROST", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "DEFROST_REAR", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "DEFROST_REAR", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "UPPER_VENT", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "UPPER_VENT", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "LOWER_VENT", - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "LOWER_VENT", + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "VOLUME_UP", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "VOLUME_UP", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "VOLUME_DOWN", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "VOLUME_DOWN", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "EJECT", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "EJECT", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "SOURCE", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "SOURCE", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "SHUFFLE", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "SHUFFLE", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false }, - { - "longPressAvailable": true, - "name": "REPEAT", - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": false - }, - "shortPressAvailable": true, - "upDownAvailable": false - } - ], - "climateControlCapabilities": [ - { - "moduleInfo": { - "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", - "allowMultipleAccess": false - }, - "acEnableAvailable": true, - "acMaxEnableAvailable": true, - "autoModeEnableAvailable": true, - "circulateAirEnableAvailable": true, - "climateEnableAvailable": true, - "currentTemperatureAvailable": true, - "defrostZone": [ - "FRONT", - "REAR", - "ALL", - "NONE" - ], - "defrostZoneAvailable": true, - "desiredTemperatureAvailable": true, - "dualModeEnableAvailable": true, - "heatedMirrorsAvailable":true, - "heatedRearWindowAvailable":true, - "heatedSteeringWheelAvailable":true, - "heatedWindshieldAvailable":true, - "fanSpeedAvailable": true, - "moduleName": "primary_climate", - "ventilationMode": [ - "UPPER", - "LOWER", - "BOTH", - "NONE" - ], - "ventilationModeAvailable": true - } - ], - "radioControlCapabilities": [ - { - "moduleInfo": { - "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", - "allowMultipleAccess": true - }, - "availableHdChannelsAvailable": true, - "hdChannelAvailable": true, - "moduleName": "radio", - "radioBandAvailable": true, - "radioEnableAvailable": true, - "radioFrequencyAvailable": true, - "rdsDataAvailable": true, - "signalChangeThresholdAvailable": true, - "signalStrengthAvailable": true, - "hdRadioEnableAvailable" : true, - "siriusxmRadioAvailable" : true, - "sisDataAvailable":true, - "stateAvailable": true - } - ], - "audioControlCapabilities": [ - { - "moduleName": "audio", - "moduleInfo": { - "moduleId": "a279fe12-4587-4d12-8514-50f4ea9e9537", - "allowMultipleAccess": true - }, - "sourceAvailable": true, - "volumeAvailable": true, - "equalizerAvailable": true, - "keepContextAvailable" : true, - "equalizerMaxChannelId": 10 - } - ], - "seatControlCapabilities": [ - { - "moduleName": "driver_seat", - "moduleInfo": { - "moduleId": "06cdec22-920e-4865-bf2e-9518463edc68", - "allowMultipleAccess": false - }, - "heatingEnabledAvailable" : true, - "coolingEnabledAvailable": true, - "heatingLevelAvailable": true, - "coolingLevelAvailable": true, - "horizontalPositionAvailable": true, - "verticalPositionAvailable" : true, - "frontVerticalPositionAvailable": true, - "backVerticalPositionAvailable": true, - "backTiltAngleAvailable": true, - "headSupportHorizontalPositionAvailable": true, - "headSupportVerticalPositionAvailable" : true, - "massageEnabledAvailable": true, - "massageModeAvailable": true, - "massageCushionFirmnessAvailable": true, - "memoryAvailable": true - } - ], - "lightControlCapabilities": { - "moduleName": "light", - "moduleInfo": { - "moduleId": "8d73e369-6a1f-4459-ab5a-6e432631881d", - "allowMultipleAccess": false - }, - "supportedLights":[ - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_HIGH_BEAM", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_HIGH_BEAM", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_LOW_BEAM", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_LOW_BEAM", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_PARKING_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_PARKING_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_FOG_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_FOG_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_DAYTIME_RUNNING_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_DAYTIME_RUNNING_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_LEFT_TURN_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FRONT_RIGHT_TURN_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_LEFT_FOG_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_RIGHT_FOG_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_LEFT_TAIL_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_RIGHT_TAIL_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_LEFT_BRAKE_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_RIGHT_BRAKE_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_LEFT_TURN_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_RIGHT_TURN_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_REGISTRATION_PLATE_LIGHT", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"HIGH_BEAMS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"LOW_BEAMS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"FOG_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"RUNNING_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"PARKING_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"BRAKE_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"REAR_REVERSING_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"SIDE_MARKER_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"LEFT_TURN_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"RIGHT_TURN_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"HAZARD_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"AMBIENT_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"OVERHEAD_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"READING_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"TRUNK_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"EXTERIOR_FRONT_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"EXTERIOR_REAR_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"EXTERIOR_LEFT_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { - "statusAvailable":true, - "densityAvailable":true, - "name":"EXTERIOR_RIGHT_LIGHTS", - "rgbColorSpaceAvailable":true - }, - { + "shortPressAvailable": true, + "upDownAvailable": false + }, + { + "longPressAvailable": true, + "name": "REPEAT", + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": false + }, + "shortPressAvailable": true, + "upDownAvailable": false + } + ], + "climateControlCapabilities": [ + { + "moduleInfo": { + "moduleId": "34045662-a9dc-4823-8435-91056d4c26cb", + "allowMultipleAccess": false + }, + "acEnableAvailable": true, + "acMaxEnableAvailable": true, + "autoModeEnableAvailable": true, + "circulateAirEnableAvailable": true, + "climateEnableAvailable": true, + "currentTemperatureAvailable": true, + "defrostZone": [ + "FRONT", + "REAR", + "ALL", + "NONE" + ], + "defrostZoneAvailable": true, + "desiredTemperatureAvailable": true, + "dualModeEnableAvailable": true, + "heatedMirrorsAvailable":true, + "heatedRearWindowAvailable":true, + "heatedSteeringWheelAvailable":true, + "heatedWindshieldAvailable":true, + "fanSpeedAvailable": true, + "moduleName": "primary_climate", + "ventilationMode": [ + "UPPER", + "LOWER", + "BOTH", + "NONE" + ], + "ventilationModeAvailable": true + } + ], + "radioControlCapabilities": [ + { + "moduleInfo": { + "moduleId": "eb7739ea-b263-4fe1-af9c-9311d1acac2d", + "allowMultipleAccess": true + }, + "availableHdChannelsAvailable": true, + "hdChannelAvailable": true, + "moduleName": "radio", + "radioBandAvailable": true, + "radioEnableAvailable": true, + "radioFrequencyAvailable": true, + "rdsDataAvailable": true, + "signalChangeThresholdAvailable": true, + "signalStrengthAvailable": true, + "hdRadioEnableAvailable" : true, + "siriusxmRadioAvailable" : true, + "sisDataAvailable":true, + "stateAvailable": true + } + ], + "audioControlCapabilities": [ + { + "moduleName": "audio", + "moduleInfo": { + "moduleId": "a279fe12-4587-4d12-8514-50f4ea9e9537", + "allowMultipleAccess": true + }, + "sourceAvailable": true, + "volumeAvailable": true, + "equalizerAvailable": true, + "keepContextAvailable" : true, + "equalizerMaxChannelId": 10 + } + ], + "seatControlCapabilities": [ + { + "moduleName": "driver_seat", + "moduleInfo": { + "moduleId": "06cdec22-920e-4865-bf2e-9518463edc68", + "allowMultipleAccess": false + }, + "heatingEnabledAvailable" : true, + "coolingEnabledAvailable": true, + "heatingLevelAvailable": true, + "coolingLevelAvailable": true, + "horizontalPositionAvailable": true, + "verticalPositionAvailable" : true, + "frontVerticalPositionAvailable": true, + "backVerticalPositionAvailable": true, + "backTiltAngleAvailable": true, + "headSupportHorizontalPositionAvailable": true, + "headSupportVerticalPositionAvailable" : true, + "massageEnabledAvailable": true, + "massageModeAvailable": true, + "massageCushionFirmnessAvailable": true, + "memoryAvailable": true + } + ], + "lightControlCapabilities": { + "moduleName": "light", + "moduleInfo": { + "moduleId": "8d73e369-6a1f-4459-ab5a-6e432631881d", + "allowMultipleAccess": false + }, + "supportedLights":[ + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_HIGH_BEAM", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_HIGH_BEAM", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_LOW_BEAM", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_LOW_BEAM", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_PARKING_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_PARKING_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_FOG_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_FOG_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_DAYTIME_RUNNING_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_DAYTIME_RUNNING_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_LEFT_TURN_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FRONT_RIGHT_TURN_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_LEFT_FOG_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_RIGHT_FOG_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_LEFT_TAIL_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_RIGHT_TAIL_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_LEFT_BRAKE_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_RIGHT_BRAKE_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_LEFT_TURN_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_RIGHT_TURN_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_REGISTRATION_PLATE_LIGHT", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"HIGH_BEAMS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"LOW_BEAMS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"FOG_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"RUNNING_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"PARKING_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"BRAKE_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"REAR_REVERSING_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"SIDE_MARKER_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"LEFT_TURN_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"RIGHT_TURN_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"HAZARD_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"AMBIENT_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"OVERHEAD_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"READING_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"TRUNK_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"EXTERIOR_FRONT_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"EXTERIOR_REAR_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"EXTERIOR_LEFT_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { + "statusAvailable":true, + "densityAvailable":true, + "name":"EXTERIOR_RIGHT_LIGHTS", + "rgbColorSpaceAvailable":true + }, + { "statusAvailable":false, "densityAvailable":false, "name":"REAR_CARGO_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"REAR_TRUCK_BED_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"REAR_TRAILER_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"LEFT_SPOT_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"RIGHT_SPOT_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"LEFT_PUDDLE_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":false, "densityAvailable":false, "name":"RIGHT_PUDDLE_LIGHTS", "rgbColorSpaceAvailable":false - }, - { + }, + { "statusAvailable":true, "densityAvailable":false, "name":"EXTERIOR_ALL_LIGHTS", "rgbColorSpaceAvailable":false - } - ] - }, - "hmiSettingsControlCapabilities": { - "moduleName": "hmiSettings", - "moduleInfo": { - "moduleId": "c8cace3c-d482-4be1-8862-624a21e34563", - "allowMultipleAccess": true - }, - "distanceUnitAvailable": true, - "temperatureUnitAvailable": true, - "displayModeUnitAvailable": true - } + } + ] + }, + "hmiSettingsControlCapabilities": { + "moduleName": "hmiSettings", + "moduleInfo": { + "moduleId": "c8cace3c-d482-4be1-8862-624a21e34563", + "allowMultipleAccess": true + }, + "distanceUnitAvailable": true, + "temperatureUnitAvailable": true, + "displayModeUnitAvailable": true } + }, + "seatLocationCapability": { + "rows": 2, + "columns": 3, + "levels": 1, + "seats": [ + { + "row": 0, + "col": 0, + "level": 0, + "rowspan": 1, + "levelspan": 1, + "colspan": 1 + } + ] } }, "VR": { - "capabilities": ["TEXT"], + "vrCapabilities": ["TEXT"], "language": "EN-US", "languages": [ "EN-US", "ES-MX", "FR-CA", "DE-DE", "ES-ES", "EN-GB", "RU-RU", "TR-TR", "PL-PL", "FR-FR", "IT-IT", "SV-SE", "PT-PT", "NL-NL", "ZH-TW", @@ -937,7 +939,8 @@ ] }, "TTS": { - "capabilities": ["TEXT"], + "speechCapabilities": ["TEXT"], + "prerecordedSpeechCapabilities": ["HELP_JINGLE"], "language": "EN-US", "languages": [ "EN-US", "ES-MX", "FR-CA", "DE-DE", "ES-ES", "EN-GB", "RU-RU", "TR-TR", "PL-PL", "FR-FR", "IT-IT", "SV-SE", "PT-PT", "NL-NL", "ZH-TW", @@ -1047,10 +1050,12 @@ } }, "VehicleInfo": { - "make": "SDL", - "model": "Generic", - "modelYear": "2019", - "trim": "SE" + "vehicleType": { + "make": "SDL", + "model": "Generic", + "modelYear": "2019", + "trim": "SE" + } }, "SyncMessageVersion": { "majorVersion": 3, diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index 31302f24c6..bd23e5b90c 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -51,6 +51,8 @@ ThreadStackSize = 20480 MixingAudioSupported = true ; In case HMI doesn’t send some capabilities to SDL, the values from the file are used by SDL HMICapabilities = hmi_capabilities.json +; Path to file containing cached response for UI.GetCapabilities/GetSupportedLanguages +HMICapabilitiesCacheFile = hmi_capabilities_cache.json ; Maximum cmdId of VR command which may be registered on SDL ; Bigger value used for system VR commands processing by SDL MaxCmdID = 2000000000 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 633bea87be..5bdebc441e 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 @@ -423,7 +423,10 @@ class ApplicationManagerImpl mobile_api::HMILevel::eType IsHmiLevelFullAllowed(ApplicationSharedPtr app); void ConnectToDevice(const std::string& device_mac) OVERRIDE; - void OnHMIStartedCooperation() OVERRIDE; + + void OnHMIReady() OVERRIDE; + + void RequestForInterfacesAvailability() OVERRIDE; void DisconnectCloudApp(ApplicationSharedPtr app) OVERRIDE; @@ -957,6 +960,7 @@ class ApplicationManagerImpl */ bool IsHMICooperating() const OVERRIDE; + void SetHMICooperating(const bool hmi_cooperating) OVERRIDE; /** * @brief Method used to send default app tts globalProperties * in case they were not provided from mobile side after defined time diff --git a/src/components/application_manager/include/application_manager/commands/request_to_hmi.h b/src/components/application_manager/include/application_manager/commands/request_to_hmi.h index e8850fbe8d..3057476937 100644 --- a/src/components/application_manager/include/application_manager/commands/request_to_hmi.h +++ b/src/components/application_manager/include/application_manager/commands/request_to_hmi.h @@ -74,6 +74,21 @@ class RequestToHMI : public CommandImpl { virtual void Run(); void SendRequest(); + /** + * @brief Updates required requests that should be send to the HMI to get + * required HMI capabilities + * @param interface_name Interface name (e.g. UI, TTS, VR, RC or VehicleInfo) + */ + void UpdateRequiredInterfaceCapabilitiesRequests( + const std::string& interface_name); + + /** + * @brief According to the specified interface sends appropriate requests to + * HMI for fetching of capabilities + * @param interface_name Interface name (e.g. UI, TTS, VR, RC or VehicleInfo) + */ + void RequestInterfaceCapabilities(const char* interface_name); + /* * @brief Retrieves application ID */ @@ -83,6 +98,22 @@ class RequestToHMI : public CommandImpl { private: DISALLOW_COPY_AND_ASSIGN(RequestToHMI); + + /** + * @brief Updates required requests that should be send to + * the HMI to get required HMI capabilities according to the passed function + * ids + * @param requests_to_send_to_hmi Collection of the function ids + */ + void UpdateRequestsRequiredForCapabilities( + const std::set& requests_to_send_to_hmi); + + /** + * @brief Sends request to HMI for fetching of capabilities according to the + * passed function ids + */ + void RequestCapabilities( + const std::set& requests_to_send_to_hmi); }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h index b7f41ca297..089105fdba 100644 --- a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h +++ b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h @@ -38,7 +38,6 @@ #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" #include "json/json.h" -#include "smart_objects/smart_object.h" #include "utils/macro.h" namespace application_manager { @@ -46,32 +45,19 @@ class ApplicationManager; class HMICapabilitiesImpl : public HMICapabilities { public: - /* + /** * @ Class constructor - * * @param app_mngr Application manager pointer */ explicit HMICapabilitiesImpl(ApplicationManager& app_mngr); - /* + /** * @brief Class destructor - * */ virtual ~HMICapabilitiesImpl(); - /* - * @brief Checks is image type(Static/Dynamic) requested by - * Mobile Device is supported on current HMI. - * @param image_type recieved type of image from Enum. - * @return Bool true if supported - */ bool VerifyImageType(const int32_t image_type) const OVERRIDE; - /** - * @brief Checks if all HMI capabilities received - * - * @return TRUE if all information received, otherwise FALSE - */ bool is_vr_cooperating() const OVERRIDE; void set_is_vr_cooperating(const bool value) OVERRIDE; @@ -90,491 +76,339 @@ class HMICapabilitiesImpl : public HMICapabilities { bool is_rc_cooperating() const OVERRIDE; void set_is_rc_cooperating(const bool value) OVERRIDE; - /* - * @brief Interface used to store information about software version of the - *target - * - * @param ccpu_version Received system/hmi software version - */ void set_ccpu_version(const std::string& ccpu_version) OVERRIDE; - /* - * @brief Returns software version of the target - * - * @return TRUE if it supported, otherwise FALSE - */ const std::string& ccpu_version() const OVERRIDE; - /* - * @brief Retrieves if mixing audio is supported by HMI - * (ie recording TTS command and playing audio) - * - * @return Current state of the mixing audio flag - */ bool attenuated_supported() const OVERRIDE; - /* - * @brief Sets state for mixing audio - * - * @param state New state to be set - */ void set_attenuated_supported(const bool state) OVERRIDE; - /* - * @brief Retrieves currently active UI language - * - * @return Currently active UI language - */ const hmi_apis::Common_Language::eType active_ui_language() const OVERRIDE; - /* - * @brief Sets currently active UI language - * - * @param language Currently active UI language - */ void set_active_ui_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves UI supported languages - * - * @return Currently supported UI languages - */ - const smart_objects::SmartObject* ui_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr ui_supported_languages() const OVERRIDE; - /* - * @brief Sets supported UI languages - * - * @param supported_languages Supported UI languages - */ void set_ui_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves currently active VR language - * - * @return Currently active VR language - */ const hmi_apis::Common_Language::eType active_vr_language() const OVERRIDE; - /* - * @brief Sets currently active VR language - * - * @param language Currently active VR language - */ void set_active_vr_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves VR supported languages - * - * @return Currently supported VR languages - */ - const smart_objects::SmartObject* vr_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr vr_supported_languages() const OVERRIDE; - /* - * @brief Sets supported VR languages - * - * @param supported_languages Supported VR languages - */ void set_vr_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves currently active TTS language - * - * @return Currently active TTS language - */ const hmi_apis::Common_Language::eType active_tts_language() const OVERRIDE; - /* - * @brief Sets currently active TTS language - * - * @param language Currently active TTS language - */ void set_active_tts_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves TTS supported languages - * - * @return Currently supported TTS languages - */ - const smart_objects::SmartObject* tts_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr tts_supported_languages() const OVERRIDE; - /* - * @brief Sets supported TTS languages - * - * @param supported_languages Supported TTS languages - */ void set_tts_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves information about the display capabilities - * - * @return Currently supported display capabilities - */ const smart_objects::SmartObjectSPtr display_capabilities() const OVERRIDE; - /* - * @brief Sets supported display capabilities - * - * @param display_capabilities supported display capabilities - */ void set_display_capabilities( const smart_objects::SmartObject& display_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the display capability - * @return Currently supported display capability - */ const smart_objects::SmartObjectSPtr system_display_capabilities() const OVERRIDE; - /* - * @brief Sets supported display capability - * @param display_capabilities supported display capability - */ void set_system_display_capabilities( const smart_objects::SmartObject& display_capabilities); - /* - * @brief Retrieves information about the HMI zone capabilities - * - * @return Currently supported HMI zone capabilities - */ const smart_objects::SmartObjectSPtr hmi_zone_capabilities() const OVERRIDE; - /* - * @brief Sets supported HMI zone capabilities - * - * @param hmi_zone_capabilities supported HMI zone capabilities - */ void set_hmi_zone_capabilities( const smart_objects::SmartObject& hmi_zone_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the SoftButton's capabilities - * - * @return Currently supported SoftButton's capabilities - */ const smart_objects::SmartObjectSPtr soft_button_capabilities() const OVERRIDE; - /* - * @brief Sets supported SoftButton's capabilities - * - * @param soft_button_capabilities supported SoftButton's capabilities - */ void set_soft_button_capabilities( const smart_objects::SmartObject& soft_button_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the Button's capabilities - * - * @return Currently supported Button's capabilities - */ const smart_objects::SmartObjectSPtr button_capabilities() const OVERRIDE; - /* - * @brief Sets supported Button's capabilities - * - * @param soft_button_capabilities supported Button's capabilities - */ void set_button_capabilities( const smart_objects::SmartObject& button_capabilities) OVERRIDE; - /* - * @brief Sets supported speech capabilities - * - * @param speech_capabilities supported speech capabilities - */ void set_speech_capabilities( const smart_objects::SmartObject& speech_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the speech capabilities - * - * @return Currently supported speech capabilities - */ const smart_objects::SmartObjectSPtr speech_capabilities() const OVERRIDE; - /* - * @brief Sets supported VR capabilities - * - * @param vr_capabilities supported VR capabilities - */ void set_vr_capabilities( const smart_objects::SmartObject& vr_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the VR capabilities - * - * @return Currently supported VR capabilities - */ const smart_objects::SmartObjectSPtr vr_capabilities() const OVERRIDE; - /* - * @brief Sets supported audio_pass_thru capabilities - * - * @param vr_capabilities supported audio_pass_thru capabilities - */ void set_audio_pass_thru_capabilities( const smart_objects::SmartObject& audio_pass_thru_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the audio_pass_thru capabilities - * - * @return Currently supported audio_pass_thru capabilities - */ const smart_objects::SmartObjectSPtr audio_pass_thru_capabilities() const OVERRIDE; - /* - * @brief Sets supported pcm_stream capabilities - * - * @param supported pcm_stream capabilities - */ void set_pcm_stream_capabilities( const smart_objects::SmartObject& pcm_stream_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the pcm_stream capabilities - * - * @return Currently supported pcm_streaming capabilities - */ const smart_objects::SmartObjectSPtr pcm_stream_capabilities() const OVERRIDE; - /* - * @brief Retrieves information about the preset bank capabilities - * - * @return Currently supported preset bank capabilities - */ const smart_objects::SmartObjectSPtr preset_bank_capabilities() const OVERRIDE; - /* - * @brief Sets supported preset bank capabilities - * - * @param soft_button_capabilities supported preset bank capabilities - */ void set_preset_bank_capabilities( const smart_objects::SmartObject& preset_bank_capabilities) OVERRIDE; - /* - * @brief Sets vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information - */ void set_vehicle_type( const smart_objects::SmartObject& vehicle_type) OVERRIDE; - /* - * @brief Retrieves vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information - */ const smart_objects::SmartObjectSPtr vehicle_type() const OVERRIDE; - /* - * @brief Retrieves information about the prerecorded speech - * - * @return Currently supported prerecorded speech - */ const smart_objects::SmartObjectSPtr prerecorded_speech() const OVERRIDE; - /* - * @brief Sets supported prerecorded speech - * - * @param prerecorded_speech supported prerecorded speech - */ void set_prerecorded_speech( const smart_objects::SmartObject& prerecorded_speech) OVERRIDE; - /* - * @brief Interface used to store information if navigation - * supported by the system - * - * @param supported Indicates if navigation supported by the system - */ void set_navigation_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves information if navi supported by the system - * - * @return TRUE if it supported, otherwise FALSE - */ bool navigation_supported() const OVERRIDE; - /* - * @brief Interface used to store information if phone call - * supported by the system - * - * @param supported Indicates if navigation supported by the sustem - */ void set_phone_call_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves information if phone call supported by the system - * - * @return TRUE if it supported, otherwise FALSE - */ bool phone_call_supported() const OVERRIDE; - /* - * @brief Interface to store whether HMI supports video streaming - * - * @param supported Indicates whether video streaming is supported by HMI - */ void set_video_streaming_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves whether HMI supports video streaming - * - * @return TRUE if it supported, otherwise FALSE - */ bool video_streaming_supported() const OVERRIDE; - /* - * @brief Interface to store whether HMI supports remote control - * - * @param supported Indicates whether video streaming is supported by HMI - */ void set_rc_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves whether HMI supports remote control - * - * @return TRUE if it supported, otherwise FALSE - */ bool rc_supported() const OVERRIDE; - /* - * @brief Interface used to store information regarding - * the navigation "System Capability" - * - * @param navigation_capability contains information related - * to the navigation system capability. - */ void set_navigation_capability( const smart_objects::SmartObject& navigation_capability) OVERRIDE; - /* - * @brief Retrieves information regarding the navigation system capability - * - * @return NAVIGATION system capability - */ - const smart_objects::SmartObject* navigation_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr navigation_capability() const OVERRIDE; - /* - * @brief Interface used to store information regarding - * the phone "System Capability" - * - * @param phone_capability contains information related - * to the phone system capability. - */ void set_phone_capability( const smart_objects::SmartObject& phone_capability) OVERRIDE; - /* - * @brief Retrieves information regarding the phone call system capability - * - * @return PHONE_CALL system capability - */ + const smart_objects::SmartObjectSPtr phone_capability() const OVERRIDE; - const smart_objects::SmartObject* phone_capability() const OVERRIDE; - - /* - * @brief Sets HMI's video streaming related capability information - * - * @param video_streaming_capability the video streaming related capabilities - */ void set_video_streaming_capability( const smart_objects::SmartObject& video_streaming_capability) OVERRIDE; - /* - * @brief Retrieves HMI's video streaming related capabilities - * - * @return HMI's video streaming related capability information - */ - const smart_objects::SmartObject* video_streaming_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr video_streaming_capability() + const OVERRIDE; void set_rc_capability( const smart_objects::SmartObject& rc_capability) OVERRIDE; - const smart_objects::SmartObject* rc_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr rc_capability() const OVERRIDE; void set_seat_location_capability( const smart_objects::SmartObject& seat_location_capability) OVERRIDE; - const smart_objects::SmartObject* seat_location_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr seat_location_capability() + const OVERRIDE; void Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE; DEPRECATED void Init(resumption::LastState* last_state) OVERRIDE; - /* - * @brief return component which follows for correctness of - * languages - * @return HMI language handler - */ HMILanguageHandler& get_hmi_language_handler() OVERRIDE; - /** - * @brief Trigger waiting for response - * @param request Request object - */ void set_handle_response_for( const smart_objects::SmartObject& request) OVERRIDE; + bool SaveCachedCapabilitiesToFile( + const std::string& interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema) OVERRIDE; + + bool DeleteCachedCapabilitiesFile() const OVERRIDE; + + bool IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType function_id) const OVERRIDE; + + void UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) OVERRIDE; + + void OnSoftwareVersionReceived(const std::string& ccpu_version) OVERRIDE; + + void UpdateCachedCapabilities() OVERRIDE; + protected: - /* + /** * @brief Loads capabilities from local file in case SDL was launched * without HMI * * @return TRUE if capabilities loaded successfully, otherwise FALSE. */ - bool load_capabilities_from_file(); - - /* - * @brief function checks if json member exists - * - * @param json_member from file hmi_capabilities.json - * @param name_of_member name which we should check - * hmi_capabilities.json - * - * @returns TRUE if member exists and returns FALSE if - * member does not exist. - */ - bool check_existing_json_member(const Json::Value& json_member, - const char* name_of_member) const OVERRIDE; + bool LoadCapabilitiesFromFile(); - /* + /** * @brief function converts json object "languages" to smart object - * * @param json_languages from file hmi_capabilities.json * @param languages - the converted object * */ void convert_json_languages_to_obj( const Json::Value& json_languages, - smart_objects::SmartObject& languages) const OVERRIDE; + smart_objects::SmartObject& languages) const; - /* + /** * @brief function that converts a single entry of audio pass thru capability * to smart object - * * @param capability json object that represents a single entry of audio pass * thru capability * @param output_so the converted object */ void convert_audio_capability_to_obj( const Json::Value& capability, - smart_objects::SmartObject& output_so) const OVERRIDE; + smart_objects::SmartObject& output_so) const; private: + /** + * @brief Checks are all updating fields are currently saved in the JSON + * structure + * @param root_node reference to root node of JSON structure + * @param interface_name name of interface to check + * @param sections_to_check reference to list of fields to check + * @return true if all fields from the list are saved in the JSON structure, + * otherwise returns false + */ + bool AllFieldsSaved(const Json::Value& root_node, + const std::string& interface_name, + const std::vector& sections_to_check) const; + + /** + * @brief Remove received interface from default initialized capabilities + * @param requested_interface interface which should be removed + */ + void RemoveFromRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface); + + /** + * @brief Gets the currently active language depending on interface + * @param interface_name name of interface of currently active language + * @return active language for specified interface + * + */ + hmi_apis::Common_Language::eType GetActiveLanguageForInterface( + const std::string& interface_name) const; + + /** + * @brief Prepares specified JSON structure according to sections which + * should be updated + * @param interface_name name of interface to prepare + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_root_node reference to JSON structure to update + */ + void PrepareJsonValueForSaving( + const char* interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_root_node) const; + + /** + * @brief Prepares specified JSON structure for UI interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareUiJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for VR interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareVrJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for TTS interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareTtsJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for Buttons interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareButtonsJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for VehicleInfo interface + * according to sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareVehicleInfoJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for RC interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareRCJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Adds appropriate request IDs to the requested required collection + * according to an interface name + * @param interface_name An interface name which requests required to send to + * the HMI + */ + void AddRequiredRequestsForCapabilities(const std::string& interface_name); + bool is_vr_cooperating_; bool is_tts_cooperating_; bool is_ui_cooperating_; @@ -587,9 +421,9 @@ class HMICapabilitiesImpl : public HMICapabilities { hmi_apis::Common_Language::eType vr_language_; hmi_apis::Common_Language::eType tts_language_; smart_objects::SmartObjectSPtr vehicle_type_; - smart_objects::SmartObject* ui_supported_languages_; - smart_objects::SmartObject* tts_supported_languages_; - smart_objects::SmartObject* vr_supported_languages_; + smart_objects::SmartObjectSPtr ui_supported_languages_; + smart_objects::SmartObjectSPtr tts_supported_languages_; + smart_objects::SmartObjectSPtr vr_supported_languages_; /* * display_capabilities_ is deprecated and replaced by * system_display_capabilities_. For backward compatibility @@ -611,15 +445,17 @@ class HMICapabilitiesImpl : public HMICapabilities { bool is_video_streaming_supported_; bool is_rc_supported_; std::string ccpu_version_; - smart_objects::SmartObject* navigation_capability_; - smart_objects::SmartObject* phone_capability_; - smart_objects::SmartObject* video_streaming_capability_; - smart_objects::SmartObject* rc_capability_; - smart_objects::SmartObject* seat_location_capability_; + smart_objects::SmartObjectSPtr navigation_capability_; + smart_objects::SmartObjectSPtr phone_capability_; + smart_objects::SmartObjectSPtr video_streaming_capability_; + smart_objects::SmartObjectSPtr rc_capability_; + smart_objects::SmartObjectSPtr seat_location_capability_; ApplicationManager& app_mngr_; HMILanguageHandler hmi_language_handler_; + std::set requests_required_for_capabilities_; + DISALLOW_COPY_AND_ASSIGN(HMICapabilitiesImpl); }; diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 8559e77061..2f50fd4a6b 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -385,6 +385,10 @@ class PolicyHandler : public PolicyHandlerInterface, const std::string& wers_country_code, const std::string& language) OVERRIDE; + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + + std::string GetCCPUVersionFromPT() const OVERRIDE; + /** * @brief Sends GetVehicleData request in case when Vechicle info is ready. */ diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 19dd6fbe3b..74cf37513b 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -479,6 +479,19 @@ extern const char* const x; extern const char* const y; } // namespace strings +namespace hmi_interface { +extern const char* basic_communication; +extern const char* buttons; +extern const char* navigation; +extern const char* sdl; +extern const char* tts; +extern const char* ui; +extern const char* vr; +extern const char* rc; +extern const char* vehicle_info; +extern const char* app_service; +} // namespace hmi_interface + namespace json { extern const char* appId; extern const char* name; @@ -590,6 +603,7 @@ extern const char* capabilities; extern const char* speech_capabilities; extern const char* prerecorded_speech_capabilities; extern const char* preset_bank_capabilities; +extern const char* on_screen_presets_available; extern const char* allowed; extern const char* vehicle_type; extern const char* did_result; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h index 36fd8bbbf9..743cf69a28 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h @@ -37,7 +37,13 @@ namespace rc_rpc_plugin { -enum capabilitiesStatus { success, missedLightName, missedParam, readOnly }; +enum capabilitiesStatus { + kInvalidStatus, + kSuccess, + kMissedLightName, + kMissedParam, + kReadOnly +}; typedef std::pair ModuleTypeCapability; class RCCapabilitiesManager { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h index 5ee2e0725c..6625641f54 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h @@ -65,8 +65,6 @@ const char kGrid[] = "grid"; const char kAllowMultipleAccess[] = "allowMultipleAccess"; -const char kSupportedLights[] = "supportedLights"; - // ClimateControlCapabilities const char kFanSpeedAvailable[] = "fanSpeedAvailable"; const char kCurrentTemperatureAvailable[] = "currentTemperatureAvailable"; @@ -88,6 +86,7 @@ const char kName[] = "name"; const char kStatusAvailable[] = "statusAvailable"; const char kDensityAvailable[] = "densityAvailable"; const char kRGBColorSpaceAvailable[] = "rgbColorSpaceAvailable"; +const char kSupportedLights[] = "supportedLights"; // RadioControlCapabilities const char kRadioBandAvailable[] = "radioBandAvailable"; @@ -100,6 +99,7 @@ const char kSignalChangeThresholdAvailable[] = "signalChangeThresholdAvailable"; const char kRadioEnableAvailable[] = "radioEnableAvailable"; const char kStateAvailable[] = "stateAvailable"; const char kSisDataAvailable[] = "sisDataAvailable"; +const char kHdChannelAvailable[] = "hdChannelAvailable"; const char kSiriusxmRadioAvailable[] = "siriusxmRadioAvailable"; @@ -128,6 +128,7 @@ const char kSourceAvailable[] = "sourceAvailable"; const char kKeepContextAvailable[] = "keepContextAvailable"; const char kVolumeAvailable[] = "volumeAvailable"; const char kEqualizerAvailable[] = "equalizerAvailable"; +const char kEqualizerMaxChannelId[] = "equalizerMaxChannelId"; // HmiSettingsCapabilities const char kDistanceUnitAvailable[] = "distanceUnitAvailable"; @@ -358,6 +359,7 @@ const char kNotFound[] = "NOT_FOUND"; const char kFront[] = "FRONT"; const char kRear[] = "REAR"; const char kAll[] = "ALL"; +const char kNone[] = "NONE"; // DefrostZone enum // TemperatureUnit enum @@ -387,8 +389,9 @@ const char kRepeat[] = "REPEAT"; // ButtonName enum // ButtonPressMode enum -const char kLong[] = "LONG"; -const char kShort[] = "SHORT"; +const char kShortPressAvailable[] = "shortPressAvailable"; +const char kLongPressAvailable[] = "longPressAvailable"; +const char kUpDownAvailable[] = "upDownAvailable"; // ButtonPressMode enum // Access mode enum diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc index 10f6303ac9..e89b260dca 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc @@ -54,13 +54,12 @@ GetInteriorVehicleDataRequest::GetInteriorVehicleDataRequest( bool GetInteriorVehicleDataRequest::ProcessCapabilities() { LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); + const auto rc_capability = hmi_capabilities_.rc_capability(); const std::string module_type = ModuleType(); const std::string module_id = ModuleId(); const ModuleUid module(module_type, module_id); - if (rc_capabilities && + if (rc_capability && !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { LOG4CXX_WARN( logger_, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc index e30d7869bd..375db9cd9d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc @@ -91,13 +91,12 @@ ReleaseInteriorVehicleDataModuleRequest:: bool ReleaseInteriorVehicleDataModuleRequest::ProcessCapabilities() { LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); + const auto rc_capability = hmi_capabilities_.rc_capability(); const std::string module_type = ModuleType(); const std::string module_id = ModuleId(); const ModuleUid module(module_type, module_id); - if (rc_capabilities && + if (rc_capability && !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { LOG4CXX_WARN( logger_, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc index c3e5e807d7..dfcc6205b1 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc @@ -84,22 +84,24 @@ mobile_apis::Result::eType PrepareResultCodeAndInfo( mobile_apis::Result::UNSUPPORTED_RESOURCE; if (message_params::kLightState == module_data_capabilities.first) { switch (module_data_capabilities.second) { - case capabilitiesStatus::missedLightName: + case capabilitiesStatus::kMissedLightName: info = "The requested LightName is not supported by the vehicle."; break; - case capabilitiesStatus::missedParam: + case capabilitiesStatus::kMissedParam: info = "The requested parameter of the given LightName is not supported " "by the vehicle."; break; - case capabilitiesStatus::readOnly: + case capabilitiesStatus::kReadOnly: info = "The requested parameter is read-only."; result_code = mobile_apis::Result::READ_ONLY; break; default: break; } - + } else if (module_data_capabilities.second == + capabilitiesStatus::kInvalidStatus) { + info = "The RC Capability is not available"; } else { info = "Accessing not supported module data."; } @@ -133,7 +135,7 @@ void SetInteriorVehicleDataRequest::Execute() { rc_capabilities_manager_.GetModuleDataCapabilities(module_data, module_id); - if (capabilitiesStatus::success != module_data_capabilities.second) { + if (capabilitiesStatus::kSuccess != module_data_capabilities.second) { SetResourceState(ModuleType(), ResourceState::FREE); std::string info; mobile_apis::Result::eType result = @@ -152,14 +154,14 @@ void SetInteriorVehicleDataRequest::Execute() { return; } - module_data_capabilities = std::make_pair("", capabilitiesStatus::success); + module_data_capabilities = std::make_pair("", capabilitiesStatus::kSuccess); if (rc_capabilities_manager_.AreReadOnlyParamsPresent( module_data, module_type, module_data_capabilities)) { LOG4CXX_DEBUG(logger_, "Request module type has READ ONLY parameters"); if (enums_value::kLight == module_data_capabilities.first && - capabilitiesStatus::success != module_data_capabilities.second) { + capabilitiesStatus::kSuccess != module_data_capabilities.second) { SetResourceState(ModuleType(), ResourceState::FREE); SendResponse( false, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 885c5ac0dd..fc342a6d86 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -157,8 +157,8 @@ void RCCommandRequest::Run() { "Remote control is disabled by user"); return; } - auto rc_capabilities = hmi_capabilities_.rc_capability(); - if (!rc_capabilities || rc_capabilities->empty()) { + auto rc_capability = hmi_capabilities_.rc_capability(); + if (!rc_capability || rc_capability->empty()) { LOG4CXX_WARN(logger_, "Accessing not supported module: " << ModuleType()); SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc index dbedd0167f..0f68769b38 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc @@ -92,7 +92,13 @@ RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilitiesArray( const std::string RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilities( const std::string& module_type) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return std::string(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); if (!rc_capabilities.keyExists(mapping(module_type))) { LOG4CXX_WARN( @@ -165,7 +171,14 @@ const bool RCCapabilitiesManagerImpl::CheckModuleIdWithCapabilities( bool RCCapabilitiesManagerImpl::CheckIfModuleExistsInCapabilities( const ModuleUid& module) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& resource_list = GetResources(); bool is_module_type_valid = false; @@ -252,7 +265,13 @@ void RCCapabilitiesManagerImpl::GetResourcesFromCapabilitiesArray( const std::vector RCCapabilitiesManagerImpl::GetResources() const { LOG4CXX_AUTO_TRACE(logger_); std::vector resources; - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return resources; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& control_caps_list = GetCapabilitiesList(); for (const auto& capability_key : control_caps_list) { if (rc_capabilities.keyExists(capability_key)) { @@ -272,7 +291,14 @@ const std::vector RCCapabilitiesManagerImpl::GetResources() const { const std::string RCCapabilitiesManagerImpl::GetModuleIdForSeatLocation( const mobile_apis::SupportedSeat::eType id) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized."); + return std::string(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto seat_capabilities = rc_capabilities[strings::kseatControlCapabilities]; if (seat_capabilities.length() > 0) { @@ -294,7 +320,13 @@ const std::string RCCapabilitiesManagerImpl::GetModuleIdForSeatLocation( bool RCCapabilitiesManagerImpl::CheckIfButtonExistInRCCaps( const mobile_apis::ButtonName::eType button) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; if (rc_capabilities.keyExists(strings::kbuttonCapabilities)) { const smart_objects::SmartObject& button_caps = rc_capabilities[strings::kbuttonCapabilities]; @@ -453,14 +485,20 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetModuleDataCapabilities( const smart_objects::SmartObject& module_data, const std::string& module_id) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return {std::string(), capabilitiesStatus::kInvalidStatus}; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& all_module_types = RCHelpers::GetModuleTypesList(); const auto& get_module_data_key = RCHelpers::GetModuleTypeToDataMapping(); const auto& get_capabilities_key = RCHelpers::GetModuleTypeToCapabilitiesMapping(); ModuleTypeCapability module_data_capabilities = - std::make_pair("", capabilitiesStatus::missedParam); + std::make_pair("", capabilitiesStatus::kMissedParam); for (const auto& module_type : all_module_types) { const auto module_data_key = get_module_data_key(module_type); @@ -501,13 +539,13 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( } if (message_params::kLightState == request_parameter) { ModuleTypeCapability light_capability = - std::make_pair("", capabilitiesStatus::success); + std::make_pair("", capabilitiesStatus::kSuccess); for (auto& light_data : *(control_data[request_parameter].asArray())) { light_capability = GetLightNameCapabilities( capabilities[strings::kSupportedLights], light_data); - if (capabilitiesStatus::success != light_capability.second) { + if (capabilitiesStatus::kSuccess != light_capability.second) { return light_capability; } } @@ -517,7 +555,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( if (message_params::kBand == request_parameter) { ModuleTypeCapability radio_capability = GetRadioBandByCapabilities( capabilities, control_data[request_parameter]); - if (capabilitiesStatus::success != radio_capability.second) { + if (capabilitiesStatus::kSuccess != radio_capability.second) { return radio_capability; } } @@ -528,12 +566,12 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( request_parameter, mobile_apis::Result::UNSUPPORTED_RESOURCE); - if (capabilitiesStatus::success != status_item_capability) { + if (capabilitiesStatus::kSuccess != status_item_capability) { return std::make_pair("", status_item_capability); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( @@ -547,7 +585,7 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( LOG4CXX_DEBUG( logger_, "Parameter " << request_parameter << " doesn't exist in capabilities."); - return capabilitiesStatus::missedParam; + return capabilitiesStatus::kMissedParam; } const std::string& caps_key = it->second; @@ -561,7 +599,7 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( LOG4CXX_DEBUG(logger_, "Capability " << caps_key << " is missed in RemoteControl capabilities"); - return capabilitiesStatus::missedParam; + return capabilitiesStatus::kMissedParam; } if (!capabilities[caps_key].asBool()) { @@ -569,14 +607,14 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( "Capability " << caps_key << " is switched off in RemoteControl capabilities"); - capabilitiesStatus status = capabilitiesStatus::missedParam; + capabilitiesStatus status = capabilitiesStatus::kMissedParam; if (mobile_apis::Result::READ_ONLY == switched_off_result) { - status = capabilitiesStatus::readOnly; + status = capabilitiesStatus::kReadOnly; } return status; } - return capabilitiesStatus::success; + return capabilitiesStatus::kSuccess; } ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightDataCapabilities( @@ -598,13 +636,13 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightDataCapabilities( request_parameter, mobile_apis::Result::READ_ONLY); - if (capabilitiesStatus::success != status_item_capability) { + if (capabilitiesStatus::kSuccess != status_item_capability) { return std::make_pair(message_params::kLightState, status_item_capability); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightNameCapabilities( @@ -619,7 +657,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightNameCapabilities( } LOG4CXX_DEBUG(logger_, "There is no such light name in capabilities"); return std::make_pair(message_params::kLightState, - capabilitiesStatus::missedLightName); + capabilitiesStatus::kMissedLightName); } ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( @@ -634,7 +672,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( << strings::kSiriusxmRadioAvailable << " is missed in RemoteControl capabilities"); return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); + capabilitiesStatus::kMissedParam); } if (!capabilities_status[strings::kSiriusxmRadioAvailable].asBool()) { LOG4CXX_DEBUG(logger_, @@ -642,10 +680,10 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( << strings::kSiriusxmRadioAvailable << " is switched off in RemoteControl capabilities"); return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); + capabilitiesStatus::kMissedParam); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } const smart_objects::SmartObject& RCCapabilitiesManagerImpl::ControlDataForType( @@ -729,7 +767,7 @@ bool RCCapabilitiesManagerImpl::AreReadOnlyParamsPresent( if (result) { module_data_capabilities = - std::make_pair(module_type, capabilitiesStatus::readOnly); + std::make_pair(module_type, capabilitiesStatus::kReadOnly); } return result; } @@ -869,7 +907,13 @@ Grid RCCapabilitiesManagerImpl::GetModuleServiceAreaFromControlCapability( Grid RCCapabilitiesManagerImpl::GetModuleServiceArea( const ModuleUid& module) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return Grid(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& module_type = module.first; const auto& capabilities_key = mapping(module_type); @@ -903,7 +947,13 @@ bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowedInControlCaps( bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowed( const ModuleUid& module) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_ERROR(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& module_type = module.first; const auto& capabilities_key = mapping(module_type); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc index fb8de0bb9c..625b2d6312 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc @@ -79,14 +79,15 @@ class ButtonPressRequestTest : public CommandRequestTest { public: ButtonPressRequestTest() - : rc_capabilities_(smart_objects::SmartType_Map) + : rc_capabilities_(std::make_shared( + smart_objects::SmartType_Map)) , mock_app_(std::make_shared >()) , rc_app_extention_( std::make_shared(kModuleId)) {} void SetUp() OVERRIDE { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); @@ -95,7 +96,7 @@ class ButtonPressRequestTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); ON_CALL(mock_policy_handler_, CheckHMIType(kPolicyAppId, @@ -140,7 +141,7 @@ class ButtonPressRequestTest } protected: - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; std::shared_ptr mock_app_; std::shared_ptr rc_app_extention_; test::components::policy_test::MockPolicyHandlerInterface diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc index 532a62df3b..82b71f1be4 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc @@ -96,7 +96,8 @@ class GetInteriorVehicleDataRequestTest , rc_app_extention2_(std::make_shared(kModuleId)) , apps_lock_(std::make_shared()) , apps_da_(apps_, apps_lock_) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) { + , rc_capabilities_(std::make_shared( + smart_objects::SmartType::SmartType_Array)) { ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(*mock_app2_, app_id()).WillByDefault(Return(kAppId2)); ON_CALL(*mock_app_, is_remote_control_supported()) @@ -131,7 +132,7 @@ class GetInteriorVehicleDataRequestTest frequency.first = max_request_in_time_frame; frequency.second = time_frame_of_allowed_requests; smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, get_settings()) .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, get_interior_vehicle_data_frequency()) @@ -151,7 +152,7 @@ class GetInteriorVehicleDataRequestTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) @@ -195,7 +196,7 @@ class GetInteriorVehicleDataRequestTest DataAccessor apps_da_; testing::NiceMock mock_rc_capabilities_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; testing::NiceMock mock_rc_consent_manger_; }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 55be43f37b..e5f96215eb 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -106,7 +106,8 @@ class RCGetInteriorVehicleDataConsentTest RCGetInteriorVehicleDataConsentTest() : mock_app_(std::make_shared >()) , command_holder(app_mngr_) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) + , rc_capabilities_(std::make_shared( + smart_objects::SmartType::SmartType_Array)) , request_controller(mock_request_controler) , rpc_protection_manager_( std::make_shared()) @@ -124,7 +125,7 @@ class RCGetInteriorVehicleDataConsentTest , rpc_plugin(mock_rpc_plugin) , optional_mock_rpc_plugin(mock_rpc_plugin) { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); @@ -143,7 +144,7 @@ class RCGetInteriorVehicleDataConsentTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) @@ -209,7 +210,7 @@ class RCGetInteriorVehicleDataConsentTest mock_interior_data_cache_; testing::NiceMock mock_interior_data_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; MockRPCPlugin mock_rpc_plugin; MockCommandFactory mock_command_factory; am::request_controller::RequestController request_controller; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc index 200e458c17..81e0fa87af 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc @@ -84,16 +84,10 @@ using namespace rc_rpc_plugin; class ReleaseInteriorVehicleDataModuleRequestTest : public CommandRequestTest { public: - ReleaseInteriorVehicleDataModuleRequestTest() : mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - TestPreCondition(); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppID)); - ON_CALL(mock_rc_capabilities_manager_, - GetDefaultModuleIdFromCapabilities(kModuleType)) - .WillByDefault(Return(kDefaultModuleID)); - } + ReleaseInteriorVehicleDataModuleRequestTest() + : mock_app_(CreateMockApp()) + , rc_capabilities_(std::make_shared( + smart_objects::SmartType::SmartType_Array)) {} MessageSharedPtr CreateBasicMessage() { MessageSharedPtr message = CreateMessage(); @@ -111,13 +105,6 @@ class ReleaseInteriorVehicleDataModuleRequestTest return message; } - void TestPreCondition() { - message_ = CreateBasicMessage(); - command_ = - CreateRCCommand( - message_); - } - template std::shared_ptr CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); @@ -134,6 +121,26 @@ class ReleaseInteriorVehicleDataModuleRequestTest } protected: + void SetUp() OVERRIDE { + TestPreCondition(); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppID)); + ON_CALL(mock_hmi_capabilities_, rc_capability()) + .WillByDefault(Return(rc_capabilities_)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, + GetDefaultModuleIdFromCapabilities(kModuleType)) + .WillByDefault(Return(kDefaultModuleID)); + } + + void TestPreCondition() { + message_ = CreateBasicMessage(); + command_ = + CreateRCCommand( + message_); + } + MessageSharedPtr message_; ReleaseCommandPtr command_; @@ -143,6 +150,7 @@ class ReleaseInteriorVehicleDataModuleRequestTest MockInteriorDataManager mock_interior_data_manager_; NiceMock mock_rc_capabilities_manager_; MockRCConsentManager mock_rc_consent_manger_; + smart_objects::SmartObjectSPtr rc_capabilities_; }; TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc index 5a822a2fe4..1e4da625b2 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc @@ -74,11 +74,12 @@ class SetInteriorVehicleDataRequestTest SetInteriorVehicleDataRequestTest() : mock_app_(std::make_shared >()) , rc_app_extention_(std::make_shared(kModuleId)) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) {} + , rc_capabilities_(std::make_shared( + smart_objects::SmartType::SmartType_Array)) {} void SetUp() OVERRIDE { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); ON_CALL( @@ -102,13 +103,14 @@ class SetInteriorVehicleDataRequestTest nullptr)) .WillByDefault(Return(true)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) .WillByDefault(Return(true)); ON_CALL(mock_rc_capabilities_manager_, GetModuleDataCapabilities(_, _)) - .WillByDefault(Return(std::make_pair("", capabilitiesStatus::success))); + .WillByDefault( + Return(std::make_pair("", capabilitiesStatus::kSuccess))); } MessageSharedPtr CreateBasicMessage() { @@ -149,7 +151,7 @@ class SetInteriorVehicleDataRequestTest std::shared_ptr rc_app_extention_; testing::NiceMock mock_rc_capabilities_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; testing::NiceMock mock_rc_consent_manger_; }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h index 9bb3d9a6fb..62be7e8836 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h @@ -62,10 +62,9 @@ class ButtonGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~ButtonGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(ButtonGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h index 8d3be68539..0b82feb1c5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h @@ -64,7 +64,12 @@ class GetSystemInfoRequest : public app_mngr::commands::RequestToHMI { /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; + + /** + * @brief onTimeOut from request controller + */ + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(GetSystemInfoRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h index d4f35a4e2a..2d3c40c3f3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h @@ -74,8 +74,7 @@ class GetSystemInfoResponse : public app_mngr::commands::ResponseFromHMI { virtual void Run(); private: - const SystemInfo GetSystemInfo( - const hmi_apis::Common_Result::eType code) const; + const SystemInfo GetSystemInfo() const; DISALLOW_COPY_AND_ASSIGN(GetSystemInfoResponse); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h index 57a90955f4..6dd06f283d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h @@ -61,10 +61,9 @@ class RCGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~RCGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(RCGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h index 305a866659..15b2e13867 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h @@ -34,7 +34,6 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_IS_READY_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" -#include "application_manager/message_helper.h" namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -78,11 +77,6 @@ class RCIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(RCIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h index d636485915..4ddd6f25fc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h @@ -61,10 +61,9 @@ class TTSGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~TTSGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h index 73ef8c5234..b00fc9cffa 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h @@ -61,10 +61,9 @@ class TTSGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~TTSGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h index a24a6446b3..802a196c46 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h @@ -63,10 +63,9 @@ class TTSGetSupportedLanguagesRequest **/ virtual ~TTSGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h index dd360eeb4a..039df31972 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h @@ -35,6 +35,8 @@ #include "application_manager/commands/request_to_hmi.h" +#include + namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -77,11 +79,6 @@ class TTSIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(TTSIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h index 58d8d0f732..32e878e733 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h @@ -61,10 +61,9 @@ class UIGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h index 842a97a717..d642beb341 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h @@ -61,10 +61,9 @@ class UIGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h index 42ea555358..9c2492b9fe 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h @@ -62,10 +62,9 @@ class UIGetSupportedLanguagesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h index 18536032b7..9bcde383e0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h @@ -35,6 +35,8 @@ #include "application_manager/commands/request_to_hmi.h" +#include + namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -77,11 +79,6 @@ class UIIsReadyRequest : public app_mngr::commands::RequestToHMI, */ virtual void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(UIIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h index 254d00452f..7f8485ffa0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h @@ -61,10 +61,9 @@ class VRGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h index 441795cfb5..abcaa35726 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h @@ -61,10 +61,9 @@ class VRGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h index ad87415a87..fb6d05b0aa 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h @@ -62,10 +62,9 @@ class VRGetSupportedLanguagesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h index 2dba80065a..cbd77087b2 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h @@ -34,7 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VR_IS_READY_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" -#include "application_manager/message_helper.h" + +#include namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -78,11 +79,6 @@ class VRIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(VRIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc index 6696689174..c0d22dcb89 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc @@ -58,6 +58,12 @@ void ButtonGetCapabilitiesRequest::Run() { SendRequest(); } +void ButtonGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc index b6ab822c47..cc3a61a9df 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc @@ -58,22 +58,32 @@ void ButtonGetCapabilitiesResponse::Run() { static_cast( (*message_)[strings::params][hmi_response::code].asInt()); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities); + if (hmi_apis::Common_Result::SUCCESS != code) { LOG4CXX_ERROR(logger_, "Error is returned. Capabilities won't be updated."); return; } - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_button_capabilities( + std::vector sections_to_update{ + hmi_response::button_capabilities}; + hmi_capabilities_.set_button_capabilities( (*message_)[strings::msg_params][hmi_response::capabilities]); if ((*message_)[strings::msg_params].keyExists( hmi_response::preset_bank_capabilities)) { - hmi_capabilities.set_preset_bank_capabilities( + sections_to_update.push_back(hmi_response::preset_bank_capabilities); + hmi_capabilities_.set_preset_bank_capabilities( (*message_)[strings::msg_params] [hmi_response::preset_bank_capabilities]); } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::buttons, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save Buttons.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc index 8546252119..7a505a46f3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc @@ -59,6 +59,11 @@ void GetSystemInfoRequest::Run() { SendRequest(); } +void GetSystemInfoRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateCachedCapabilities(); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc index baff925a4e..7a7d015e21 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc @@ -53,38 +53,38 @@ GetSystemInfoResponse::~GetSystemInfoResponse() {} void GetSystemInfoResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - const hmi_apis::Common_Result::eType code = - static_cast( - (*message_)[strings::params][hmi_response::code].asInt()); + const auto code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); - const SystemInfo& info = GetSystemInfo(code); + hmi_capabilities_.set_ccpu_version(policy_handler_.GetCCPUVersionFromPT()); + + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_WARN(logger_, "GetSystemError returns an error code " << code); + hmi_capabilities_.UpdateCachedCapabilities(); + policy_handler_.SetPreloadedPtFlag(false); + return; + } + + const SystemInfo& info = GetSystemInfo(); - // We have to set preloaded flag as false in policy table on any response - // of GetSystemInfo (SDLAQ-CRS-2365) policy_handler_.OnGetSystemInfo( info.ccpu_version, info.wers_country_code, info.language); + + hmi_capabilities_.OnSoftwareVersionReceived(info.ccpu_version); } -const SystemInfo GetSystemInfoResponse::GetSystemInfo( - const hmi_apis::Common_Result::eType code) const { +const SystemInfo GetSystemInfoResponse::GetSystemInfo() const { SystemInfo info; - if (hmi_apis::Common_Result::SUCCESS != code) { - LOG4CXX_WARN(logger_, "GetSystemError returns an error code " << code); - return info; - } info.ccpu_version = (*message_)[strings::msg_params]["ccpu_version"].asString(); info.wers_country_code = (*message_)[strings::msg_params]["wersCountryCode"].asString(); - const uint32_t lang_code = - (*message_)[strings::msg_params]["language"].asUInt(); - info.language = application_manager::MessageHelper::CommonLanguageToString( - static_cast(lang_code)); - - hmi_capabilities_.set_ccpu_version(info.ccpu_version); + const auto lang_code = static_cast( + (*message_)[strings::msg_params]["language"].asUInt()); + info.language = MessageHelper::CommonLanguageToString(lang_code); return info; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc index da3612b043..c9270fd80b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc @@ -54,7 +54,7 @@ OnReadyNotification::~OnReadyNotification() {} void OnReadyNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - application_manager_.OnHMIStartedCooperation(); + application_manager_.OnHMIReady(); event_engine::Event event(hmi_apis::FunctionID::BasicCommunication_OnReady); event.set_smart_object(*message_); event.raise(application_manager_.event_dispatcher()); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc index f89baad737..293857f8d5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc @@ -59,20 +59,31 @@ OnTTSLanguageChangeNotification::~OnTTSLanguageChangeNotification() {} void OnTTSLanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_tts_language( + hmi_capabilities_.set_active_tts_language( static_cast( (*message_)[strings::msg_params][strings::language].asInt())); /* need to clarify, because unchanged VR cause WRONG_LANGUAGE on Register */ - hmi_capabilities.set_active_vr_language( + hmi_capabilities_.set_active_vr_language( static_cast( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.OnLanguageChange response to cache"); + } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); + hmi_capabilities_.active_ui_language(); (*message_)[strings::params][strings::function_id] = static_cast(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc index 697b2036c4..995d69cc45 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc @@ -59,17 +59,22 @@ OnUILanguageChangeNotification::~OnUILanguageChangeNotification() {} void OnUILanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_ui_language( + hmi_capabilities_.set_active_ui_language( static_cast( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = (*message_)[strings::msg_params][strings::language]; (*message_)[strings::msg_params][strings::language] = - hmi_capabilities.active_vr_language(); + hmi_capabilities_.active_vr_language(); (*message_)[strings::params][strings::function_id] = static_cast(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc index c308af9b92..1500f272ab 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc @@ -60,14 +60,19 @@ OnVRLanguageChangeNotification::~OnVRLanguageChangeNotification() {} void OnVRLanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_vr_language( + hmi_capabilities_.set_active_vr_language( static_cast( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); + hmi_capabilities_.active_ui_language(); (*message_)[strings::params][strings::function_id] = static_cast(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc index d8ad6087a6..d882dcd6e7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc @@ -57,6 +57,12 @@ void RCGetCapabilitiesRequest::Run() { SendRequest(); } +void RCGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc index 128b111c5e..910c12e979 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc @@ -53,13 +53,26 @@ RCGetCapabilitiesResponse::~RCGetCapabilitiesResponse() {} void RCGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector sections_to_update; bool rc_capability_exists = (*message_)[strings::msg_params].keyExists(strings::rc_capability); if (rc_capability_exists) { - hmi_capabilities.set_rc_capability( + hmi_capabilities_.set_rc_capability( (*message_)[strings::msg_params][strings::rc_capability]); + sections_to_update.push_back(strings::rc_capability); } bool seat_location_capability_exists = @@ -67,11 +80,18 @@ void RCGetCapabilitiesResponse::Run() { strings::seat_location_capability); if (seat_location_capability_exists) { - hmi_capabilities.set_seat_location_capability( + hmi_capabilities_.set_seat_location_capability( (*message_)[strings::msg_params][strings::seat_location_capability]); + sections_to_update.push_back(strings::seat_location_capability); } - hmi_capabilities.set_rc_supported(rc_capability_exists); + hmi_capabilities_.set_rc_supported(rc_capability_exists); + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::rc, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save RC.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc index 5e4af1503a..4ea0d43dc3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc @@ -31,6 +31,9 @@ */ #include "sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h" + +#include + #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -77,11 +80,13 @@ void RCIsReadyRequest::on_event(const event_engine::Event& event) { if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_RC)) { + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_RC isn't available"); return; } - SendMessageToHMI(); + RequestInterfaceCapabilities(hmi_interface::rc); break; } default: { @@ -93,14 +98,7 @@ void RCIsReadyRequest::on_event(const event_engine::Event& event) { void RCIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void RCIsReadyRequest::SendMessageToHMI() { - std::shared_ptr get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::RC_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::rc); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc index 9baaabf401..85f0b93b8c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc @@ -57,6 +57,11 @@ void TTSGetCapabilitiesRequest::Run() { SendRequest(); } +void TTSGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc index c0581a6380..e6edcdb365 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc @@ -52,19 +52,38 @@ TTSGetCapabilitiesResponse::~TTSGetCapabilitiesResponse() {} void TTSGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector sections_to_update; if ((*message_)[strings::msg_params].keyExists( hmi_response::speech_capabilities)) { - hmi_capabilities.set_speech_capabilities( + sections_to_update.push_back(hmi_response::speech_capabilities); + hmi_capabilities_.set_speech_capabilities( (*message_)[strings::msg_params][hmi_response::speech_capabilities]); } if ((*message_)[strings::msg_params].keyExists( hmi_response::prerecorded_speech_capabilities)) { - hmi_capabilities.set_prerecorded_speech( + sections_to_update.push_back(hmi_response::prerecorded_speech_capabilities); + hmi_capabilities_.set_prerecorded_speech( (*message_)[strings::msg_params] [hmi_response::prerecorded_speech_capabilities]); } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc index 7d2c15a9bf..d62c9627f5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc @@ -57,6 +57,11 @@ void TTSGetLanguageRequest::Run() { SendRequest(); } +void TTSGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc index 627056dce1..1487fd7915 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc @@ -56,6 +56,18 @@ void TTSGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + Common_Language::eType language = Common_Language::INVALID_ENUM; if ((*message_).keyExists(strings::msg_params) && @@ -66,6 +78,12 @@ void TTSGetLanguageResponse::Run() { hmi_capabilities_.set_active_tts_language(language); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_DEBUG(logger_, "Failed to save TTS.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc index 2cb47380d5..5d758c84b7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void TTSGetSupportedLanguagesRequest::Run() { SendRequest(); } +void TTSGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc index a70d1c89a3..baa10394c5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc @@ -59,11 +59,23 @@ void TTSGetSupportedLanguagesResponse::Run() { static_cast( (*message_)[strings::params][hmi_response::code].asInt()); - if (hmi_apis::Common_Result::SUCCESS == code) { - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); - hmi_capabilities.set_tts_supported_languages( - (*message_)[strings::msg_params][hmi_response::languages]); + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + hmi_capabilities_.set_tts_supported_languages( + (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.GetSupportedLanguages response to cache"); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc index 89b5961895..4ae737bec4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc @@ -31,7 +31,6 @@ */ #include "sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h" -#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -74,11 +73,13 @@ void TTSIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_tts_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_TTS)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::tts); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_TTS isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::tts); break; } default: { @@ -90,25 +91,7 @@ void TTSIsReadyRequest::on_event(const event_engine::Event& event) { void TTSIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void TTSIsReadyRequest::SendMessageToHMI() { - std::shared_ptr get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::tts); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc index 5f8704b3e5..32c19eabcd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc @@ -57,6 +57,11 @@ void UIGetCapabilitiesRequest::Run() { SendRequest(); } +void UIGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc index 45ae49f205..c5a76612f6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc @@ -53,86 +53,112 @@ UIGetCapabilitiesResponse::~UIGetCapabilitiesResponse() {} void UIGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector sections_to_update; const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; if (msg_params.keyExists(hmi_response::display_capabilities)) { - hmi_capabilities.set_display_capabilities( + sections_to_update.push_back(hmi_response::display_capabilities); + hmi_capabilities_.set_display_capabilities( msg_params[hmi_response::display_capabilities]); } if (msg_params.keyExists(hmi_response::hmi_zone_capabilities)) { - hmi_capabilities.set_hmi_zone_capabilities( + sections_to_update.push_back(hmi_response::hmi_zone_capabilities); + hmi_capabilities_.set_hmi_zone_capabilities( msg_params[hmi_response::hmi_zone_capabilities]); } if (msg_params.keyExists(hmi_response::soft_button_capabilities)) { - hmi_capabilities.set_soft_button_capabilities( + sections_to_update.push_back(hmi_response::soft_button_capabilities); + hmi_capabilities_.set_soft_button_capabilities( msg_params[hmi_response::soft_button_capabilities]); } // use newer parameter "audioPassThruCapabilitiesList" when available if (msg_params.keyExists(strings::audio_pass_thru_capabilities_list)) { - hmi_capabilities.set_audio_pass_thru_capabilities( + sections_to_update.push_back(strings::audio_pass_thru_capabilities); + hmi_capabilities_.set_audio_pass_thru_capabilities( msg_params[strings::audio_pass_thru_capabilities_list]); } else if (msg_params.keyExists(strings::audio_pass_thru_capabilities)) { smart_objects::SmartObject audio_pass_thru_capabilities_list( smart_objects::SmartType_Array); audio_pass_thru_capabilities_list[0] = msg_params[strings::audio_pass_thru_capabilities]; - hmi_capabilities.set_audio_pass_thru_capabilities( + sections_to_update.push_back(strings::audio_pass_thru_capabilities); + hmi_capabilities_.set_audio_pass_thru_capabilities( audio_pass_thru_capabilities_list); } if (msg_params.keyExists(strings::hmi_capabilities)) { if (msg_params[strings::hmi_capabilities].keyExists(strings::navigation)) { - hmi_capabilities.set_navigation_supported( + sections_to_update.push_back(strings::navigation); + hmi_capabilities_.set_navigation_supported( msg_params[strings::hmi_capabilities][strings::navigation].asBool()); } if (msg_params[strings::hmi_capabilities].keyExists(strings::phone_call)) { - hmi_capabilities.set_phone_call_supported( + sections_to_update.push_back(strings::phone_call); + hmi_capabilities_.set_phone_call_supported( msg_params[strings::hmi_capabilities][strings::phone_call].asBool()); } if (msg_params[strings::hmi_capabilities].keyExists( strings::video_streaming)) { - hmi_capabilities.set_video_streaming_supported( + sections_to_update.push_back(strings::video_streaming); + hmi_capabilities_.set_video_streaming_supported( msg_params[strings::hmi_capabilities][strings::video_streaming] .asBool()); } } if (msg_params.keyExists(strings::system_capabilities)) { - if (msg_params[strings::system_capabilities].keyExists( - strings::navigation_capability)) { - hmi_capabilities.set_navigation_capability( - msg_params[strings::system_capabilities] - [strings::navigation_capability]); + auto& system_capabilities_so = msg_params[strings::system_capabilities]; + + if (system_capabilities_so.keyExists(strings::navigation_capability)) { + sections_to_update.push_back(strings::navigation_capability); + hmi_capabilities_.set_navigation_capability( + system_capabilities_so[strings::navigation_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::phone_capability)) { - hmi_capabilities.set_phone_capability( - msg_params[strings::system_capabilities][strings::phone_capability]); + if (system_capabilities_so.keyExists(strings::phone_capability)) { + sections_to_update.push_back(strings::phone_capability); + hmi_capabilities_.set_phone_capability( + system_capabilities_so[strings::phone_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::video_streaming_capability)) { - hmi_capabilities.set_video_streaming_capability( - msg_params[strings::system_capabilities] - [strings::video_streaming_capability]); + if (system_capabilities_so.keyExists(strings::video_streaming_capability)) { + sections_to_update.push_back(strings::video_streaming_capability); + hmi_capabilities_.set_video_streaming_capability( + system_capabilities_so[strings::video_streaming_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::display_capabilities)) { - hmi_capabilities.set_system_display_capabilities( - msg_params[strings::system_capabilities] - [strings::display_capabilities]); + if (system_capabilities_so.keyExists(strings::display_capabilities)) { + sections_to_update.push_back(strings::display_capabilities); + hmi_capabilities_.set_system_display_capabilities( + system_capabilities_so[strings::display_capabilities]); } } if (msg_params.keyExists(strings::pcm_stream_capabilities)) { - hmi_capabilities.set_pcm_stream_capabilities( + sections_to_update.push_back(strings::pcm_stream_capabilities); + hmi_capabilities_.set_pcm_stream_capabilities( msg_params[strings::pcm_stream_capabilities]); } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc index d3b44d1168..948adbdece 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc @@ -57,6 +57,11 @@ void UIGetLanguageRequest::Run() { SendRequest(); } +void UIGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc index 2a5c0ab016..e32dbf3c47 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc @@ -56,6 +56,17 @@ UIGetLanguageResponse::~UIGetLanguageResponse() {} void UIGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } Common_Language::eType language = Common_Language::INVALID_ENUM; @@ -67,6 +78,12 @@ void UIGetLanguageResponse::Run() { hmi_capabilities_.set_active_ui_language(language); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, "Failed to save UI.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc index 0665612525..0001af9203 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void UIGetSupportedLanguagesRequest::Run() { SendRequest(); } +void UIGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc index 19ee62e51d..53704b3705 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc @@ -59,11 +59,23 @@ void UIGetSupportedLanguagesResponse::Run() { static_cast( (*message_)[strings::params][hmi_response::code].asInt()); - if (hmi_apis::Common_Result::SUCCESS == code) { - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages); - hmi_capabilities.set_ui_supported_languages( - (*message_)[strings::msg_params][hmi_response::languages]); + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + hmi_capabilities_.set_ui_supported_languages( + (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.GetSupportedLanguages response to cache"); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc index 2546b704b2..4882095d42 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc @@ -31,7 +31,6 @@ */ #include "sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h" -#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -73,11 +72,13 @@ void UIIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_ui_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_UI)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::ui); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_UI isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::ui); break; } default: { @@ -89,25 +90,7 @@ void UIIsReadyRequest::on_event(const event_engine::Event& event) { void UIIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void UIIsReadyRequest::SendMessageToHMI() { - std::shared_ptr get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::ui); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc index b06bfa0e77..dd0d78cf2d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc @@ -57,6 +57,11 @@ void VRGetCapabilitiesRequest::Run() { SendRequest(); } +void VRGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc index 80c308ea40..79d532bff8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc @@ -52,11 +52,32 @@ VRGetCapabilitiesResponse::~VRGetCapabilitiesResponse() {} void VRGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities); - hmi_capabilities.set_vr_capabilities( - (*message_)[strings::msg_params][strings::vr_capabilities]); + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + std::vector sections_to_update; + if (msg_params.keyExists(strings::vr_capabilities)) { + sections_to_update.push_back(strings::vr_capabilities); + hmi_capabilities_.set_vr_capabilities(msg_params[strings::vr_capabilities]); + } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc index 84179f6357..3aa36aee33 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc @@ -57,6 +57,11 @@ void VRGetLanguageRequest::Run() { SendRequest(); } +void VRGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc index 6b7fec736d..462ccc529c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc @@ -56,6 +56,17 @@ VRGetLanguageResponse::~VRGetLanguageResponse() {} void VRGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } Common_Language::eType language = Common_Language::INVALID_ENUM; @@ -67,6 +78,12 @@ void VRGetLanguageResponse::Run() { hmi_capabilities_.set_active_vr_language(language); + std::vector sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, "Failed to save VR.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc index 351940bf68..5755b91ab6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void VRGetSupportedLanguagesRequest::Run() { SendRequest(); } +void VRGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc index 4c725267fa..59602cf10a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc @@ -60,10 +60,20 @@ void VRGetSupportedLanguagesResponse::Run() { static_cast( (*message_)[strings::params][hmi_response::code].asInt()); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages); + if (hmi_apis::Common_Result::SUCCESS == code) { HMICapabilities& hmi_capabilities = hmi_capabilities_; hmi_capabilities.set_vr_supported_languages( (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR( + logger_, "Failed to save VR.GetSupportedLanguages response to cache"); + } } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc index 12414eab10..f65f58f423 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc @@ -73,11 +73,13 @@ void VRIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_vr_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_VR)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::vr); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_VR isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::vr); break; } default: { @@ -89,25 +91,7 @@ void VRIsReadyRequest::on_event(const event_engine::Event& event) { void VRIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void VRIsReadyRequest::SendMessageToHMI() { - std::shared_ptr get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::vr); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc index 19584fb055..27cac83fad 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc @@ -460,8 +460,7 @@ bool ChangeRegistrationRequest::PrepareResponseParameters( bool ChangeRegistrationRequest::IsLanguageSupportedByUI( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* ui_languages = - hmi_capabilities.ui_supported_languages(); + const auto ui_languages = hmi_capabilities.ui_supported_languages(); if (!ui_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -482,8 +481,7 @@ bool ChangeRegistrationRequest::IsLanguageSupportedByUI( bool ChangeRegistrationRequest::IsLanguageSupportedByVR( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* vr_languages = - hmi_capabilities.vr_supported_languages(); + const auto vr_languages = hmi_capabilities.vr_supported_languages(); if (!vr_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -504,8 +502,7 @@ bool ChangeRegistrationRequest::IsLanguageSupportedByVR( bool ChangeRegistrationRequest::IsLanguageSupportedByTTS( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* tts_languages = - hmi_capabilities.tts_supported_languages(); + const auto tts_languages = hmi_capabilities.tts_supported_languages(); if (!tts_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc new file mode 100644 index 0000000000..f3d8dd4f93 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2020, 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/button_get_capabilities_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace button_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::ButtonGetCapabilitiesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class ButtonGetCapabilitiesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(ButtonGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(ButtonGetCapabilitiesRequestTest, + onTimeOut_ButtonsGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace button_get_capabilities_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/button_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc index 7d9ed899a6..f90611f58d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc @@ -86,6 +86,7 @@ TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeSuccess_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)); EXPECT_CALL(mock_hmi_capabilities_, set_preset_bank_capabilities(preset_bank_capabilities_)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -102,6 +103,23 @@ TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeAborted_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_preset_bank_capabilities(preset_bank_capabilities_)) .Times(0); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(ButtonGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponsePtr command(CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc index 11589683be..30d125ff46 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc @@ -126,11 +126,27 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { static_cast(lang_code))) .Times(0); - EXPECT_CALL(mock_policy_handler_, OnGetSystemInfo("", "", "")); + EXPECT_CALL(mock_hmi_capabilities_, UpdateCachedCapabilities()); + EXPECT_CALL(mock_policy_handler_, SetPreloadedPtFlag(false)); command->Run(); } +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UpdateCapabilities_Called) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, OnSoftwareVersionReceived(ccpu_version)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + } // namespace get_system_info_response } // namespace hmi_commands_test } // namespace commands_test 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 26f7a63872..3819c720f8 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 @@ -545,7 +545,7 @@ TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { std::shared_ptr command = CreateCommand(message); - EXPECT_CALL(app_mngr_, OnHMIStartedCooperation()); + EXPECT_CALL(app_mngr_, OnHMIReady()); EXPECT_CALL(app_mngr_, event_dispatcher()); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc new file mode 100644 index 0000000000..f7da89df0b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020, 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/rc_get_capabilities_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::RCGetCapabilitiesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class RCGetCapabilitiesRequestTest + : public CommandsTest {}; + +TEST_F(RCGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(RCGetCapabilitiesRequestTest, + onTimeOut_OnCapabilityInitialized_RemoveRCGetCapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); +} + +} // namespace rc_get_capabilities_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/rc_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc index 67c36dce9c..22ecb014b0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc @@ -166,6 +166,24 @@ TEST_F(RCGetCapabilitiesResponseTest, RUN_SUCCESSS) { EXPECT_CALL(mock_hmi_capabilities_, set_rc_capability(rc_capability_so)); EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(true)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(RCGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + RCGetCapabilitiesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc index 539c0efeb3..b569ecb83f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc @@ -113,8 +113,14 @@ class RCIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)) + .WillOnce(Return(true)); + } + RCIsReadyRequestPtr command_; - am::MockHmiInterfaces mock_hmi_interfaces_; }; TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { @@ -123,6 +129,7 @@ TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::RC_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_rc_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -149,6 +156,7 @@ TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::RC_IsReady); PrepareEvent(is_message_contain_param, event, is_rc_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_rc_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -157,6 +165,7 @@ TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { } TEST_F(RCIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc new file mode 100644 index 0000000000..bae6b6082e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2020, 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/tts_get_capabilities_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetCapabilitiesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetCapabilitiesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetCapabilitiesRequestTest, onTimeOut_TTSGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_capabilities_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/tts_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc index c7b96f1acf..2479b0a28e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc @@ -52,16 +52,20 @@ using testing::_; namespace strings = ::application_manager::strings; namespace hmi_response = ::application_manager::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; namespace { -const std::string kText = "TEXT"; -} +const std::string kText{"TEXT"}; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; +} // namespace class TTSGetCapabilitiesResponseTest : public CommandsTest {}; TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = kText; @@ -70,50 +74,82 @@ TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { set_speech_capabilities(SmartObject(kText))); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr command( CreateCommand(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlySpeech_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(SmartObject(kText))); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr command( CreateCommand(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlyPrerecorded_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = kText; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr command( CreateCommand(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_Nothing_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr command( CreateCommand(msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc new file mode 100644 index 0000000000..a0bf0887db --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/tts_get_language_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetLanguageRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetLanguageRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetLanguageRequestTest, onTimeOut_TTSGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_language_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/tts_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc index c0d23cb34b..4aeef5198b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc @@ -51,10 +51,13 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; namespace { const Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class TTSGetLanguageResponseTest @@ -63,22 +66,28 @@ class TTSGetLanguageResponseTest TEST_F(TTSGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); @@ -86,10 +95,31 @@ TEST_F(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(TTSGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..1561e1def5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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/tts_get_supported_languages_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetSupportedLanguagesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetSupportedLanguagesRequestTest, + onTimeOut_TTSGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_supported_languages_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/tts_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc index c0f187a85f..e09d3198d7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc @@ -57,6 +57,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using application_manager::commands::ResponseFromHMI; using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesResponse; @@ -95,6 +96,9 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_tts_supported_languages(( *command_msg)[strings::msg_params][hmi_response::languages])); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -115,6 +119,7 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_tts_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -122,6 +127,23 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(TTSGetSupportedLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace tts_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc new file mode 100644 index 0000000000..e758bfca1f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2020, 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/tts_is_ready_request.h" + +#include +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::TTSIsReadyRequest; + +typedef std::shared_ptr RequestToHMIPtr; +typedef std::shared_ptr TTSIsReadyRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSIsReadyRequestTest + : public CommandRequestTest { + public: + TTSIsReadyRequestTest() : command_(CreateCommand()) {} + + void SetUpExpectations(const bool is_tts_cooperating_available, + const bool should_message_be_sent, + const bool message_contains_param, + const am::HmiInterfaces::InterfaceState state) { + if (should_message_be_sent) { + ExpectSendMessagesToHMI(); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_tts_cooperating(is_tts_cooperating_available)); + + if (message_contains_param) { + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr language = + std::make_shared( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(language, _)); + + smart_objects::SmartObjectSPtr support_language = + std::make_shared( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(support_language, _)); + + smart_objects::SmartObjectSPtr capabilities = + std::make_shared( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities, _)); + } + + void PrepareEvent(const bool message_contains_param, + const bool is_tts_cooperating_available, + Event& out_event) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (message_contains_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_tts_cooperating_available; + } + out_event.set_smart_object(*msg); + } + + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)) + .WillOnce(Return(true)); + } + + TTSIsReadyRequestPtr command_; +}; + +TEST_F(TTSIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const auto state = am::HmiInterfaces::STATE_NOT_RESPONSE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_NOT_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsnet) { + const bool is_tts_cooperating_available = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_HMIDoestRespond_SendMessageToHMIByTimeout_CacheIsAbsent) { + HMICapabilitiesExpectations(); + ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->onTimeOut(); +} + +} // namespace tts_is_ready_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/ui_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc new file mode 100644 index 0000000000..1057a89cc6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/ui_get_capabilities_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetCapabilitiesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetCapabilitiesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetCapabilitiesRequestTest, onTimeOut_UIGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_capabilities_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/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc index e6db817fed..cf701caf51 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -51,6 +51,7 @@ using ::testing::NiceMock; namespace am = ::application_manager; namespace strings = am::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using application_manager::commands::ResponseFromHMI; using sdl_rpc_plugin::commands::UIGetCapabilitiesResponse; @@ -99,6 +100,7 @@ TEST_F(UIGetCapabilitiesResponseTest, RUN_SetDisplay_SUCCESSS) { EXPECT_CALL(mock_hmi_capabilities_, set_display_capabilities(display_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -119,6 +121,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetSoftButton_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_soft_button_capabilities(soft_button_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -138,6 +141,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_hmi_zone_capabilities(hmi_zone_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -162,6 +166,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { EXPECT_CALL( mock_hmi_capabilities_, set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -187,6 +192,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThruList_SUCCESS) { EXPECT_CALL( mock_hmi_capabilities_, set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -206,6 +212,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetNavigation_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_navigation_supported( hmi_capabilities_so[strings::navigation].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -225,6 +232,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetPhoneCall_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_phone_call_supported( hmi_capabilities_so[strings::phone_call].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -244,6 +252,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreaming_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_video_streaming_supported( hmi_capabilities_so[strings::video_streaming].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -268,6 +277,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetNavigationCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_navigation_capability(navigation_capability_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -289,6 +299,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetPhonenCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_phone_capability(phone_capability_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -339,6 +350,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_video_streaming_capability(video_streaming_capability)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -362,21 +374,36 @@ TEST_F(UIGetCapabilitiesResponseTest, SetSystemDisplayCapabilities_SUCCESS) { command->Run(); } -TEST_F(UIGetCapabilitiesResponseTest, SetPCMStreamCapabilities_SUCCESS) { +TEST_F(UIGetCapabilitiesResponseTest, + SaveCachedCapabilitiesToFileCall_SUCCESS) { MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::pcm_stream_capabilities] = + (*command_msg)[strings::msg_params][strings::system_capabilities] = smart_objects::SmartObject(smart_objects::SmartType_Map); ResponseFromHMIPtr command( CreateCommand(command_msg)); - const auto& pcm_capabilities_so = - (*command_msg)[strings::msg_params][strings::pcm_stream_capabilities]; - EXPECT_CALL(mock_hmi_capabilities_, - set_pcm_stream_capabilities(pcm_capabilities_so)); + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); ASSERT_TRUE(command->Init()); + command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc new file mode 100644 index 0000000000..c944f1b49b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/ui_get_language_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetLanguageRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetLanguageRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetLanguageRequestTest, onTimeOut_UIGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_language_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/ui_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc index 7e8040543d..d3edf074bd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc @@ -52,6 +52,7 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; typedef NiceMock< @@ -60,6 +61,8 @@ typedef NiceMock< namespace { const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class UIGetLanguageResponseTest @@ -68,33 +71,58 @@ class UIGetLanguageResponseTest TEST_F(UIGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(UIGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(UIGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..251b6b7d58 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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/ui_get_supported_languages_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetSupportedLanguagesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetSupportedLanguagesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetSupportedLanguagesRequestTest, + onTimeOut_UIGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_supported_languages_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/ui_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc index 10cf244bcf..d73519734d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc @@ -54,6 +54,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using sdl_rpc_plugin::commands::UIGetSupportedLanguagesResponse; typedef std::shared_ptr @@ -91,6 +92,9 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_ui_supported_languages((supported_languages))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -109,6 +113,7 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_ui_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -116,6 +121,23 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(UIGetSupportedLanguagesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace ui_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc index 837b8438dc..a82ad39d83 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc @@ -141,17 +141,33 @@ class UIIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL( + mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities(hmi_apis::FunctionID::UI_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)) + .WillOnce(Return(true)); + } + UIIsReadyRequestPtr command_; policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; }; TEST_F(UIIsReadyRequestTest, - OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { const bool is_ui_cooperating_available = false; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::UI_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_ui_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -161,7 +177,7 @@ TEST_F(UIIsReadyRequestTest, } TEST_F(UIIsReadyRequestTest, - OnEvent_KeyAvailableEqualToFalse_StateNotAvailable) { + OnEvent_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { const bool is_ui_cooperating_available = false; const bool is_send_message_to_hmi = false; const bool is_message_contain_param = true; @@ -174,12 +190,14 @@ TEST_F(UIIsReadyRequestTest, command_->on_event(event); } -TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { +TEST_F(UIIsReadyRequestTest, + OnEvent_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsent) { const bool is_ui_cooperating_available = true; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::UI_IsReady); PrepareEvent(is_message_contain_param, event, is_ui_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_ui_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -187,7 +205,8 @@ TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { command_->on_event(event); } -TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS) { +TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS_CacheIsAbsent) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc index 96f3b38fbf..92e3fa1187 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc @@ -58,7 +58,7 @@ typedef std::shared_ptr UpdateSDLRequestPtr; namespace { const uint32_t kConnectionKey = 2u; const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class UpdateSDLRequestTest : public CommandsTest {}; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc index 62ffc6be4d..f0d431ac86 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc @@ -55,7 +55,7 @@ typedef std::shared_ptr UpdateSDLResponsePtr; namespace { const uint32_t kConnectionKey = 2u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class UpdateSDLResponseTest : public CommandsTest { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc new file mode 100644 index 0000000000..cef87f06b4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/vr_get_capabilities_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetCapabilitiesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetCapabilitiesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetCapabilitiesRequestTest, onTimeOut_VRGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_capabilities_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/vr_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc index 21acf2bb70..99024df485 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc @@ -51,6 +51,7 @@ using ::testing::NiceMock; namespace am = ::application_manager; namespace strings = am::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using sdl_rpc_plugin::commands::VRGetCapabilitiesResponse; @@ -95,6 +96,26 @@ TEST_F(VRGetCapabilitiesResponseTest, RUN_SUCCESSS) { (*command_msg)[strings::msg_params][strings::vr_capabilities]; EXPECT_CALL(mock_hmi_capabilities_, set_vr_capabilities(vr_capabilities_so)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(VRGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VRGetCapabilitiesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc new file mode 100644 index 0000000000..6235b41691 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/vr_get_language_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetLanguageRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetLanguageRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetLanguageRequestTest, onTimeOut_VRGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_language_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/vr_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc index 8b00b4dded..d927195fd5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc @@ -52,6 +52,7 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; typedef NiceMock< @@ -60,6 +61,8 @@ typedef NiceMock< namespace { const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class VRGetLanguageResponseTest @@ -68,22 +71,28 @@ class VRGetLanguageResponseTest TEST_F(VRGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr command( CreateCommand(msg)); @@ -91,10 +100,31 @@ TEST_F(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(VRGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..73657528e9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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/vr_get_supported_languages_request.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetSupportedLanguagesRequest; + +typedef std::shared_ptr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetSupportedLanguagesRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + RequestToHMIPtr command( + CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetSupportedLanguagesRequestTest, + onTimeOut_VRGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_supported_languages_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/vr_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc index b81823624c..2d51ee9d8a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc @@ -54,6 +54,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using sdl_rpc_plugin::commands::VRGetSupportedLanguagesResponse; typedef std::shared_ptr @@ -91,6 +92,9 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_vr_supported_languages((supported_languages))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -109,6 +113,7 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_vr_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -116,6 +121,23 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(VRGetSupportedLanguagesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace vr_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc index 9bb8e4c2d5..3d2a46707e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc @@ -68,9 +68,8 @@ class VRIsReadyRequestTest bool is_send_message_to_hmi, bool is_message_contain_param, am::HmiInterfaces::InterfaceState state) { - const bool is_send_message_by_timeout = false; if (is_send_message_to_hmi) { - ExpectSendMessagesToHMI(is_send_message_by_timeout); + ExpectSendMessagesToHMI(); } EXPECT_CALL(mock_hmi_capabilities_, set_is_vr_cooperating(is_vr_cooperating_available)); @@ -91,7 +90,7 @@ class VRIsReadyRequestTest .WillOnce(Return(state)); } - void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + void ExpectSendMessagesToHMI() { smart_objects::SmartObjectSPtr language( new smart_objects::SmartObject(smart_objects::SmartType_Map)); EXPECT_CALL(mock_message_helper_, @@ -127,15 +126,32 @@ class VRIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL( + mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities(hmi_apis::FunctionID::VR_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)) + .WillOnce(Return(true)); + } + VRIsReadyRequestPtr command_; }; -TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { +TEST_F(VRIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { const bool is_vr_cooperating_available = false; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::VR_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_vr_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -143,7 +159,8 @@ TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { +TEST_F(VRIsReadyRequestTest, + Run_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { const bool is_vr_cooperating_available = false; const bool is_send_message_to_hmi = false; const bool is_message_contain_param = true; @@ -156,12 +173,14 @@ TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { +TEST_F(VRIsReadyRequestTest, + Run_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsnet) { const bool is_vr_cooperating_available = true; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::VR_IsReady); PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_vr_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -169,9 +188,10 @@ TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { - const bool is_send_message_by_timeout = true; - ExpectSendMessagesToHMI(is_send_message_by_timeout); +TEST_F(VRIsReadyRequestTest, + Run_HMIDoestRespond_SendMessageToHMIByTimeout_CacheIsAbsent) { + HMICapabilitiesExpectations(); + ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc index 4394c6fe5e..9736bb380b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc @@ -103,11 +103,11 @@ class ChangeRegistrationRequestTest (*supported_languages_)[0] = static_cast(mobile_apis::Language::EN_US); EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); @@ -242,11 +242,11 @@ class ChangeRegistrationRequestTest void ExpectationsHmiCapabilities( smart_objects::SmartObjectSPtr supported_languages) { EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); } void ResultCommandExpectations(MessageSharedPtr msg, @@ -381,11 +381,11 @@ TEST_F(ChangeRegistrationRequestTest, (*supported_languages_)[0] = static_cast(mobile_apis::Language::EN_US); EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); 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 6376570106..a42aa61400 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 @@ -201,6 +201,8 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(smart_objects::SmartObjectSPtr())); ON_CALL(mock_hmi_capabilities_, pcm_stream_capabilities()) .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, seat_location_capability()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); ON_CALL(app_mngr_settings_, supported_diag_modes()) .WillByDefault(ReturnRef(kDummyDiagModes)); ON_CALL(mock_policy_handler_, GetAppRequestTypes(_, _)) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h index 7f2e8389ad..74f12c07d4 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h @@ -59,10 +59,9 @@ class VIGetVehicleTypeRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VIGetVehicleTypeRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VIGetVehicleTypeRequest); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h index fa9bfebad4..96f8c8ecb8 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h @@ -75,11 +75,6 @@ class VIIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(VIIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc index 250584bd12..e8df12ca5c 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc @@ -54,6 +54,12 @@ void VIGetVehicleTypeRequest::Run() { SendRequest(); } +void VIGetVehicleTypeRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); +} + } // namespace commands } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc index fb6eadf747..dcc73d26f3 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc @@ -50,10 +50,29 @@ VIGetVehicleTypeResponse::~VIGetVehicleTypeResponse() {} void VIGetVehicleTypeResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast( + (*message_)[strings::params][hmi_response::code].asInt()); - hmi_capabilities.set_vehicle_type( + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector sections_to_update{hmi_response::vehicle_type}; + hmi_capabilities_.set_vehicle_type( (*message_)[strings::msg_params][hmi_response::vehicle_type]); + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vehicle_info, + sections_to_update, + message_->getSchema())) { + LOG4CXX_ERROR( + logger_, "Failed to save VehicleInfo.GetVehicleType response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc index 93781a7420..3525be059d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc @@ -31,7 +31,9 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_is_ready_request.h" -#include "application_manager/message_helper.h" + +#include + #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/rpc_service.h" @@ -79,10 +81,12 @@ void VIIsReadyRequest::on_event(const event_engine::Event& event) { LOG4CXX_INFO( logger_, "HmiInterfaces::HMI_INTERFACE_VehicleInfo isn't available"); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); return; } - SendMessageToHMI(); + RequestInterfaceCapabilities(hmi_interface ::vehicle_info); break; } default: { @@ -94,15 +98,7 @@ void VIIsReadyRequest::on_event(const event_engine::Event& event) { void VIIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void VIIsReadyRequest::SendMessageToHMI() { - std::shared_ptr get_type( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_GetVehicleType, - application_manager_)); - rpc_service_.ManageHMICommand(get_type); + RequestInterfaceCapabilities(hmi_interface ::vehicle_info); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc index ea8dab0366..48df3d03bd 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc @@ -70,7 +70,7 @@ typedef std::shared_ptr VIGetVehicleDataResponsePtr; namespace { const uint32_t kConnectionKey = 2u; const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class VIGetVehicleDataResponseTest diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc new file mode 100644 index 0000000000..20bf34f2ca --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020, 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/vi_get_vehicle_type_request.h" + +#include + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_type_request { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using ::testing::_; +using vehicle_info_plugin::commands::VIGetVehicleTypeRequest; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VIGetVehicleTypeRequestTest + : public VICommandRequestTest { + public: + MessageSharedPtr CreateCommandMsg() { + auto command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + return command_msg; + } +}; + +TEST_F(VIGetVehicleTypeRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + auto command = CreateCommandVI(command_msg); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F( + VIGetVehicleTypeRequestTest, + onTimeOut_VIGetVehicleTypeRequestTimeoutExpired_UpdateRequestsRequiredForVIGetVehicleType) { + MessageSharedPtr command_msg = CreateCommandMsg(); + auto command(CreateCommandVI(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); +} + +} // namespace vi_get_vehicle_type_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc new file mode 100644 index 0000000000..8239905df7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2020, 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/vi_get_vehicle_type_response.h" + +#include +#include + +#include "gtest/gtest.h" + +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/response_from_hmi.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_type_response { + +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; +using vehicle_info_plugin::commands::VIGetVehicleTypeResponse; + +typedef std::shared_ptr VIGetVehicleTypeResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kVehicleType{"vehicle_type"}; +} // namespace + +class VIGetVehicleTypeResponseTest + : public VICommandRequestTest {}; + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeSuccess_ChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI(command_msg); + + EXPECT_CALL( + mock_hmi_capabilities_, + set_vehicle_type( + (*command_msg)[strings::msg_params][hmi_response::vehicle_type])); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vehicle_info, _, _)); + ASSERT_TRUE(command->Init()); + + command->Run(); + EXPECT_TRUE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeNotSuccess_DontChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, set_vehicle_type(_)).Times(0); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +} // namespace vi_get_vehicle_type_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc index c083bf4d60..f207faad77 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -32,6 +32,9 @@ #include "hmi/vi_is_ready_request.h" +#include +#include + #include "gtest/gtest.h" #include "application_manager/event_engine/event.h" @@ -55,25 +58,32 @@ using ::testing::_; using ::testing::Return; using ::testing::ReturnRef; namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; using am::event_engine::Event; using vehicle_info_plugin::commands::VIIsReadyRequest; typedef std::shared_ptr VIIsReadyRequestPtr; +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + class VIIsReadyRequestTest : public VICommandRequestTest { public: VIIsReadyRequestTest() : command_(CreateCommandVI()) {} void SetUpExpectations(bool is_vi_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, + bool should_message_be_sent, + bool message_contains_param, am::HmiInterfaces::InterfaceState state) { EXPECT_CALL(mock_hmi_capabilities_, set_is_ivi_cooperating(is_vi_cooperating_available)); - if (is_message_contain_param) { + if (message_contains_param) { EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); EXPECT_CALL(mock_hmi_interfaces_, @@ -90,7 +100,7 @@ class VIIsReadyRequestTest GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) .WillOnce(Return(state)); - if (is_send_message_to_hmi) { + if (should_message_be_sent) { ExpectSendMessagesToHMI(); } } @@ -104,61 +114,102 @@ class VIIsReadyRequestTest EXPECT_CALL(mock_rpc_service_, ManageHMICommand(ivi_type, _)); } - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_vi_cooperating_available = false) { + void PrepareEvent(bool message_contains_param, + bool is_vi_cooperating_available, + Event& out_event) { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { + if (message_contains_param) { (*msg)[am::strings::msg_params][am::strings::available] = is_vi_cooperating_available; } - event.set_smart_object(*msg); + out_event.set_smart_object(*msg); + } + + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)) + .WillOnce(Return(true)); } VIIsReadyRequestPtr command_; }; +TEST_F(VIIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + VIIsReadyRequestPtr command = CreateCommandVI(command_msg); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const auto state = am::HmiInterfaces::STATE_NOT_RESPONSE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_NOT_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { const bool is_vi_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); + HMICapabilitiesExpectations(); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->onTimeOut(); } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index bd3f4b5f08..5e1ae3bc3a 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -845,9 +845,8 @@ void ApplicationManagerImpl::ConnectToDevice(const std::string& device_mac) { connection_handler().ConnectToDevice(handle); } -void ApplicationManagerImpl::OnHMIStartedCooperation() { +void ApplicationManagerImpl::OnHMIReady() { LOG4CXX_AUTO_TRACE(logger_); - hmi_cooperating_ = true; #ifdef WEBSOCKET_SERVER_TRANSPORT_SUPPORT connection_handler_->CreateWebEngineDevice(); @@ -855,6 +854,29 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { MessageHelper::SendGetSystemInfoRequest(*this); + std::shared_ptr is_navi_ready( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::Navigation_IsReady, *this)); + rpc_service_->ManageHMICommand(is_navi_ready); + + std::shared_ptr mixing_audio_supported_request( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::BasicCommunication_MixingAudioSupported, + *this)); + rpc_service_->ManageHMICommand(mixing_audio_supported_request); + resume_controller().ResetLaunchTime(); + + RefreshCloudAppInformation(); + policy_handler_->TriggerPTUOnStartupIfRequired(); +} + +void ApplicationManagerImpl::RequestForInterfacesAvailability() { + LOG4CXX_AUTO_TRACE(logger_); + std::shared_ptr is_ivi_ready( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_IsReady, *this)); + rpc_service_->ManageHMICommand(is_ivi_ready); + std::shared_ptr is_vr_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_IsReady, *this)); @@ -870,36 +892,18 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { *this)); rpc_service_->ManageHMICommand(is_ui_ready); - std::shared_ptr is_navi_ready( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::Navigation_IsReady, *this)); - rpc_service_->ManageHMICommand(is_navi_ready); - - std::shared_ptr is_ivi_ready( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_IsReady, *this)); - rpc_service_->ManageHMICommand(is_ivi_ready); - std::shared_ptr is_rc_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::RC_IsReady, *this)); rpc_service_->ManageHMICommand(is_rc_ready); - std::shared_ptr button_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::Buttons_GetCapabilities, *this)); - rpc_service_->ManageHMICommand(button_capabilities); - - std::shared_ptr mixing_audio_supported_request( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::BasicCommunication_MixingAudioSupported, - *this)); - rpc_service_->ManageHMICommand(mixing_audio_supported_request); - resume_controller().ResetLaunchTime(); - - RefreshCloudAppInformation(); - - policy_handler_->TriggerPTUOnStartupIfRequired(); + if (hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)) { + std::shared_ptr button_capabilities( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::Buttons_GetCapabilities, *this)); + rpc_service_->ManageHMICommand(button_capabilities); + } } std::string ApplicationManagerImpl::PolicyIDByIconUrl(const std::string url) { @@ -3020,7 +3024,9 @@ void ApplicationManagerImpl::HeadUnitReset( GetPolicyHandler().UnloadPolicyLibrary(); resume_controller().StopSavePersistentDataTimer(); - + if (!hmi_capabilities_->DeleteCachedCapabilitiesFile()) { + LOG4CXX_ERROR(logger_, "Failed to remove HMI capabilities cache file"); + } const std::string storage_folder = get_settings().app_storage_folder(); file_system::RemoveDirectory(storage_folder, true); ClearAppsPersistentData(); @@ -3031,7 +3037,9 @@ void ApplicationManagerImpl::HeadUnitReset( GetPolicyHandler().ClearUserConsent(); resume_controller().StopSavePersistentDataTimer(); - + if (!hmi_capabilities_->DeleteCachedCapabilitiesFile()) { + LOG4CXX_ERROR(logger_, "Failed to remove HMI capabilities cache file"); + } ClearAppsPersistentData(); break; } @@ -3130,7 +3138,7 @@ void ApplicationManagerImpl::SendOnSDLClose() { void ApplicationManagerImpl::UnregisterAllApplications() { LOG4CXX_DEBUG(logger_, "Unregister reason " << unregister_reason_); - hmi_cooperating_ = false; + SetHMICooperating(false); bool is_ignition_off = false; using namespace mobile_api::AppInterfaceUnregisteredReason; using namespace helpers; @@ -4091,6 +4099,10 @@ bool ApplicationManagerImpl::IsHMICooperating() const { return hmi_cooperating_; } +void ApplicationManagerImpl::SetHMICooperating(const bool hmi_cooperating) { + hmi_cooperating_ = hmi_cooperating; +} + void ApplicationManagerImpl::OnApplicationListUpdateTimer() { LOG4CXX_DEBUG(logger_, "Application list update timer finished"); const bool is_new_app_registered = registered_during_timer_execution_; 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 3f279679a3..d20039bf70 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -927,21 +927,25 @@ std::string GetComponentNameFromInterface( const HmiInterfaces::InterfaceID& interface) { switch (interface) { case HmiInterfaces::HMI_INTERFACE_Buttons: - return "Buttons"; + return hmi_interface::buttons; case HmiInterfaces::HMI_INTERFACE_BasicCommunication: - return "BasicCommunication"; + return hmi_interface::basic_communication; case HmiInterfaces::HMI_INTERFACE_VR: - return "VR"; + return hmi_interface::vr; case HmiInterfaces::HMI_INTERFACE_TTS: - return "TTS"; + return hmi_interface::tts; case HmiInterfaces::HMI_INTERFACE_UI: - return "UI"; + return hmi_interface::ui; case HmiInterfaces::HMI_INTERFACE_Navigation: - return "Navigation"; + return hmi_interface::navigation; case HmiInterfaces::HMI_INTERFACE_VehicleInfo: - return "VehicleInfo"; + return hmi_interface::vehicle_info; case HmiInterfaces::HMI_INTERFACE_SDL: - return "SDL"; + return hmi_interface::sdl; + case HmiInterfaces::HMI_INTERFACE_RC: + return hmi_interface::rc; + case HmiInterfaces::HMI_INTERFACE_AppService: + return hmi_interface::app_service; default: return "Unknown type"; } 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 1acbc9ace7..ac34d091af 100644 --- a/src/components/application_manager/src/commands/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/request_to_hmi.cc @@ -31,10 +31,43 @@ */ #include "application_manager/commands/request_to_hmi.h" +#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace application_manager { +namespace { +static const std::set tts_request_ids{ + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::TTS_GetSupportedLanguages}; + +static const std::set vr_request_ids{ + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::VR_GetSupportedLanguages}; + +static const std::set ui_request_ids{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::UI_GetSupportedLanguages}; + +static const std::set rc_request_ids{ + hmi_apis::FunctionID::RC_GetCapabilities}; + +static const std::set vehicle_info_request_ids{ + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + +static std::map > + interface_requests{ + {std::string(hmi_interface::ui), ui_request_ids}, + {std::string(hmi_interface::vr), vr_request_ids}, + {std::string(hmi_interface::tts), tts_request_ids}, + {std::string(hmi_interface::rc), rc_request_ids}, + {std::string(hmi_interface::vehicle_info), vehicle_info_request_ids}}; + +} // namespace + namespace commands { bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager, @@ -92,6 +125,57 @@ void RequestToHMI::SendRequest() { rpc_service_.SendMessageToHMI(message_); } +void RequestToHMI::RequestInterfaceCapabilities(const char* interface_name) { + LOG4CXX_DEBUG( + logger_, + "Request capabilities for the " << interface_name << " interface"); + + const auto& request_ids = interface_requests[std::string(interface_name)]; + RequestCapabilities(request_ids); +} + +void RequestToHMI::UpdateRequestsRequiredForCapabilities( + const std::set& requests_to_send_to_hmi) { + for (auto request_id : requests_to_send_to_hmi) { + hmi_capabilities_.UpdateRequestsRequiredForCapabilities(request_id); + } +} + +void RequestToHMI::UpdateRequiredInterfaceCapabilitiesRequests( + const std::string& interface_name) { + LOG4CXX_DEBUG( + logger_, + "Update requests required for the " << interface_name << " interface"); + + const auto& request_ids = interface_requests[std::string(interface_name)]; + UpdateRequestsRequiredForCapabilities(request_ids); +} + +void RequestToHMI::RequestCapabilities( + const std::set& requests_to_send_to_hmi) { + LOG4CXX_DEBUG(logger_, + "There are " << requests_to_send_to_hmi.size() + << " requests to send to the HMI"); + + for (const auto& function_id : requests_to_send_to_hmi) { + if (hmi_capabilities_.IsRequestsRequiredForCapabilities(function_id)) { + std::shared_ptr request_so( + MessageHelper::CreateModuleInfoSO(function_id, application_manager_)); + + switch (function_id) { + case hmi_apis::FunctionID::UI_GetLanguage: + case hmi_apis::FunctionID::VR_GetLanguage: + case hmi_apis::FunctionID::TTS_GetLanguage: + hmi_capabilities_.set_handle_response_for(*request_so); + break; + default: + break; + } + rpc_service_.ManageHMICommand(request_so); + } + } +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index 6a0fbf78e3..11300bc684 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -30,17 +30,22 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/hmi_capabilities_impl.h" + #include #include "application_manager/application_manager.h" -#include "application_manager/hmi_capabilities_impl.h" #include "application_manager/message_helper.h" +#include "application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h" #include "application_manager/smart_object_keys.h" #include "config_profile/profile.h" #include "formatters/CFormatterJsonBase.h" #include "interfaces/HMI_API.h" +#include "smart_objects/enum_schema_item.h" #include "smart_objects/smart_object.h" #include "utils/file_system.h" +#include "utils/helpers.h" +#include "utils/jsoncpp_reader_wrapper.h" #include "utils/logger.h" namespace application_manager { @@ -53,6 +58,8 @@ std::map vr_enum_capabilities; std::map tts_enum_capabilities; +std::map + tts_enum_prerecorded_speech; std::map button_enum_name; std::map text_fields_enum_name; @@ -98,6 +105,22 @@ void InitCapabilities() { tts_enum_capabilities.insert(std::make_pair( std::string("FILE"), hmi_apis::Common_SpeechCapabilities::FILE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("HELP_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::HELP_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("INITIAL_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::INITIAL_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("LISTEN_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::LISTEN_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("POSITIVE_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::POSITIVE_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("NEGATIVE_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::NEGATIVE_JINGLE)); + button_enum_name.insert( std::make_pair(std::string("OK"), hmi_apis::Common_ButtonName::OK)); button_enum_name.insert(std::make_pair( @@ -416,6 +439,33 @@ void InitCapabilities() { } // namespace +namespace { +/** + * @brief Saves smart object content into the JSON node + * @param field_name name of the field to save + * @param schema reference to schema to unapply + * @param object_to_save pointer to object to save + * @param out_json_node JSON node for the output result + */ +void save_hmi_capability_field_to_json( + const std::string& field_name, + smart_objects::CSmartSchema schema, + smart_objects::SmartObjectSPtr object_to_save, + Json::Value& out_json_node) { + if (!object_to_save) { + return; + } + namespace Formatters = ns_smart_device_link::ns_json_handler::formatters; + smart_objects::SmartObject formatted_object(smart_objects::SmartType_Map); + formatted_object[strings::msg_params][field_name] = *object_to_save; + schema.unapplySchema(formatted_object); // converts enums back to strings + Json::Value temp_value; + Formatters::CFormatterJsonBase::objToJsonValue(formatted_object, temp_value); + out_json_node[field_name] = temp_value[strings::msg_params][field_name]; +} + +} // namespace + HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) : is_vr_cooperating_(false) , is_tts_cooperating_(false) @@ -463,15 +513,7 @@ HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) } } -HMICapabilitiesImpl::~HMICapabilitiesImpl() { - delete ui_supported_languages_; - delete tts_supported_languages_; - delete vr_supported_languages_; - delete navigation_capability_; - delete phone_capability_; - delete video_streaming_capability_; - delete rc_capability_; -} +HMICapabilitiesImpl::~HMICapabilitiesImpl() {} bool HMICapabilitiesImpl::VerifyImageType(const int32_t image_type) const { auto capabilities = display_capabilities(); @@ -567,27 +609,23 @@ HMICapabilitiesImpl::active_tts_language() const { void HMICapabilitiesImpl::set_ui_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (ui_supported_languages_) { - delete ui_supported_languages_; - } - ui_supported_languages_ = new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared(supported_languages); + ui_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_tts_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (tts_supported_languages_) { - delete tts_supported_languages_; - } - tts_supported_languages_ = - new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared(supported_languages); + tts_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_vr_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (vr_supported_languages_) { - delete vr_supported_languages_; - } - vr_supported_languages_ = new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared(supported_languages); + vr_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_display_capabilities( @@ -595,7 +633,7 @@ void HMICapabilitiesImpl::set_display_capabilities( if (app_mngr_.IsSOStructValid( hmi_apis::StructIdentifiers::Common_DisplayCapabilities, display_capabilities)) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(display_capabilities); display_capabilities_.swap(new_value); } @@ -609,71 +647,69 @@ void HMICapabilitiesImpl::set_system_display_capabilities( void HMICapabilitiesImpl::set_hmi_zone_capabilities( const smart_objects::SmartObject& hmi_zone_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(hmi_zone_capabilities); hmi_zone_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_soft_button_capabilities( const smart_objects::SmartObject& soft_button_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(soft_button_capabilities); soft_buttons_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_button_capabilities( const smart_objects::SmartObject& button_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(button_capabilities); button_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_vr_capabilities( const smart_objects::SmartObject& vr_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(vr_capabilities); vr_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_speech_capabilities( const smart_objects::SmartObject& speech_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(speech_capabilities); speech_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_audio_pass_thru_capabilities( const smart_objects::SmartObject& audio_pass_thru_capabilities) { - smart_objects::SmartObjectSPtr new_value = - std::make_shared( - audio_pass_thru_capabilities); + auto new_value = std::make_shared( + audio_pass_thru_capabilities); audio_pass_thru_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_pcm_stream_capabilities( const smart_objects::SmartObject& pcm_stream_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(pcm_stream_capabilities); pcm_stream_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_preset_bank_capabilities( const smart_objects::SmartObject& preset_bank_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(preset_bank_capabilities); preset_bank_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_vehicle_type( const smart_objects::SmartObject& vehicle_type) { - smart_objects::SmartObjectSPtr new_value = - std::make_shared(vehicle_type); + auto new_value = std::make_shared(vehicle_type); vehicle_type_.swap(new_value); } void HMICapabilitiesImpl::set_prerecorded_speech( const smart_objects::SmartObject& prerecorded_speech) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared(prerecorded_speech); prerecorded_speech_.swap(new_value); } @@ -695,51 +731,42 @@ void HMICapabilitiesImpl::set_rc_supported(const bool supported) { void HMICapabilitiesImpl::set_navigation_capability( const smart_objects::SmartObject& navigation_capability) { - if (navigation_capability_) { - delete navigation_capability_; - } - navigation_capability_ = - new smart_objects::SmartObject(navigation_capability); + auto new_value = + std::make_shared(navigation_capability); + navigation_capability_.swap(new_value); } void HMICapabilitiesImpl::set_phone_capability( const smart_objects::SmartObject& phone_capability) { - if (phone_capability_) { - delete phone_capability_; - } - phone_capability_ = new smart_objects::SmartObject(phone_capability); + auto new_value = + std::make_shared(phone_capability); + phone_capability_.swap(new_value); } void HMICapabilitiesImpl::set_video_streaming_capability( const smart_objects::SmartObject& video_streaming_capability) { - if (video_streaming_capability_) { - delete video_streaming_capability_; - } - video_streaming_capability_ = - new smart_objects::SmartObject(video_streaming_capability); + auto new_value = + std::make_shared(video_streaming_capability); + video_streaming_capability_.swap(new_value); } void HMICapabilitiesImpl::set_rc_capability( const smart_objects::SmartObject& rc_capability) { - if (rc_capability_) { - delete rc_capability_; - } - rc_capability_ = new smart_objects::SmartObject(rc_capability); + auto new_value = std::make_shared(rc_capability); + rc_capability_.swap(new_value); } void HMICapabilitiesImpl::set_seat_location_capability( const smart_objects::SmartObject& seat_location_capability) { - if (seat_location_capability_) { - delete seat_location_capability_; - } - seat_location_capability_ = - new smart_objects::SmartObject(seat_location_capability); + auto new_value = + std::make_shared(seat_location_capability); + seat_location_capability_.swap(new_value); } void HMICapabilitiesImpl::Init( resumption::LastStateWrapperPtr last_state_wrapper) { hmi_language_handler_.Init(last_state_wrapper); - if (false == load_capabilities_from_file()) { + if (!LoadCapabilitiesFromFile()) { LOG4CXX_ERROR(logger_, "file hmi_capabilities.json was not loaded"); } else { LOG4CXX_INFO(logger_, "file hmi_capabilities.json was loaded"); @@ -774,18 +801,18 @@ bool HMICapabilitiesImpl::is_rc_cooperating() const { return is_rc_cooperating_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::ui_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::ui_supported_languages() const { return ui_supported_languages_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::vr_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::vr_supported_languages() const { return vr_supported_languages_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::tts_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::tts_supported_languages() const { return tts_supported_languages_; } @@ -868,33 +895,174 @@ bool HMICapabilitiesImpl::rc_supported() const { return is_rc_supported_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::navigation_capability() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::navigation_capability() const { return navigation_capability_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::phone_capability() +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::phone_capability() const { return phone_capability_; } -const smart_objects::SmartObject* +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::video_streaming_capability() const { return video_streaming_capability_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::rc_capability() const { +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::rc_capability() + const { return rc_capability_; } -const smart_objects::SmartObject* +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::seat_location_capability() const { return seat_location_capability_; } -bool HMICapabilitiesImpl::load_capabilities_from_file() { +/** + * @brief Checks if JSON member exists + * @param json_member reference to JSON structure to check + * @param name_of_member name which we should be checked + * @returns true if member exists, otherwise returns false + */ +bool JsonIsMemberSafe(const Json::Value& json_member, + const char* name_of_member) { + return !json_member.isNull() && json_member.isMember(name_of_member); +} + +/** + * @brief Converts specified string to appropriate enum value + * according to schema + * @return converted enum value + */ +template +EnumType ConvertStringToEnum(const std::string& str) { + using ns_smart_device_link::ns_smart_objects::EnumConversionHelper; + EnumType value; + if (EnumConversionHelper::StringToEnum(str, &value)) { + return value; + } + + return EnumType::INVALID_ENUM; +} + +/** + * @brief Converts the JSON array of string type into the SmartArray of enums + * @param json_array JSON value containing array + * @param out_so_array output SmartArray + */ +template +void ConvertJsonArrayToSoArray(const Json::Value& json_array, + smart_objects::SmartObject& out_so_array) { + out_so_array = + smart_objects::SmartObject(smart_objects::SmartType::SmartType_Array); + for (uint32_t i = 0; i < json_array.size(); ++i) { + out_so_array[i] = ConvertStringToEnum(json_array[i].asString()); + } +} + +/** + * @brief Helper class for obtaining proper capabilities JSON value considering + * case if it were overriden by cache + */ +struct JsonCapabilitiesGetter { + public: + /** + * @brief JsonCapabilitiesGetter constructor + * @param json_default_node reference to the main JSON capabilities node + * @param json_cache_node reference to cached JSON capabilities node + */ + JsonCapabilitiesGetter(Json::Value& json_default_node, + Json::Value& json_cache_node) + : json_default_node_(json_default_node) + , json_cache_node_(json_cache_node) {} + + JsonCapabilitiesGetter(JsonCapabilitiesGetter&& other) { + std::swap(json_default_node_, other.json_default_node_); + std::swap(json_cache_node_, other.json_cache_node_); + } + + bool IsInterfaceJsonMemberExists(const char* interface_name) { + return JsonIsMemberSafe(json_cache_node_, interface_name) || + JsonIsMemberSafe(json_default_node_, interface_name); + } + + /** + * @brief GetJsonMember gets JSON value for a specified JSON member from + * cached JSON node if member exists, otherwise main JSON node will be + * taken + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetJsonMember( + const char* member_name, + hmi_apis::FunctionID::eType request_id, + std::set& default_initialized_capabilities) { + if (JsonIsMemberSafe(json_cache_node_, member_name)) { + return GetCachedJsonMember(member_name); + } + + LOG4CXX_DEBUG(logger_, + "Add request ID: " << request_id + << " for the interface: " << member_name); + default_initialized_capabilities.insert(request_id); + + if (JsonIsMemberSafe(json_default_node_, member_name)) { + return GetMainJsonMember(member_name); + } + + return Json::Value::null; + } + + /** + * @brief GetMainJsonMember gets JSON value for a specified JSON member from + * the main JSON node + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetMainJsonMember(const char* member_name) { + return json_default_node_.get(member_name, Json::Value::null); + } + + /** + * @brief GetCachedJsonMember gets JSON value for a specified JSON member + * from the cached JSON node + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetCachedJsonMember(const char* member_name) { + return json_cache_node_.get(member_name, Json::Value::null); + } + + private: + Json::Value json_default_node_; + Json::Value json_cache_node_; +}; + +/** + * @brief Gets the JSON node related to the specified interface name. + * @param interface_name Interface name which JSON node should be retreive from + * the main JSON node + * @return JsonCapabilitiesGetter instance initialized by default JSON node and + * cache JSON node for the specified interface + */ + +JsonCapabilitiesGetter GetInterfaceGetter( + const char* interface_name, JsonCapabilitiesGetter& json_root_getter) { + auto interface_default_node = + json_root_getter.GetMainJsonMember(interface_name); + auto interface_cache_node = + json_root_getter.GetCachedJsonMember(interface_name); + + JsonCapabilitiesGetter getter(interface_default_node, interface_cache_node); + return getter; +} + +bool HMICapabilitiesImpl::LoadCapabilitiesFromFile() { std::string json_string; - std::string file_name = app_mngr_.get_settings().hmi_capabilities_file_name(); + const std::string file_name = + app_mngr_.get_settings().hmi_capabilities_file_name(); if (!file_system::FileExists(file_name)) { return false; @@ -904,45 +1072,82 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { return false; } + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + Json::Value root_json_override; + + if (file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, + "HMI capabilities cache was found: " << cache_file_name); + + std::string cache_json_string; + if (!file_system::ReadFile(cache_file_name, cache_json_string)) { + LOG4CXX_DEBUG( + logger_, + "Failed to read data from cache file. Cache will be ignored"); + } + + try { + utils::JsonReader reader; + std::string json(cache_json_string.begin(), cache_json_string.end()); + if (!reader.parse(json, &root_json_override)) { + LOG4CXX_ERROR(logger_, + "Cached JSON file is invalid. Deleting the file"); + file_system::DeleteFile(cache_file_name); + root_json_override = + Json::Value::null; // Just to clear intermediate state of value + } + } catch (...) { + return false; + } + } + try { - Json::CharReaderBuilder reader_builder; - const std::unique_ptr reader_( - reader_builder.newCharReader()); - JSONCPP_STRING err; Json::Value root_json; - const size_t json_len = json_string.length(); - - const bool result = reader_->parse( - json_string.c_str(), json_string.c_str() + json_len, &root_json, &err); - if (!result) { - LOG4CXX_DEBUG(logger_, "Json parsing fails: " << err); + utils::JsonReader reader; + std::string json(json_string.begin(), json_string.end()); + if (!reader.parse(json, &root_json)) { + LOG4CXX_DEBUG(logger_, "Default JSON parsing fails"); return false; } + + JsonCapabilitiesGetter json_root_getter(root_json, root_json_override); // UI - if (check_existing_json_member(root_json, "UI")) { - Json::Value ui = root_json.get("UI", Json::Value::null); - if (check_existing_json_member(ui, "language")) { - const std::string lang = ui.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::ui)) { + auto json_ui_getter = + GetInterfaceGetter(hmi_interface::ui, json_root_getter); + + auto ui_language_node = + json_ui_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::UI_GetLanguage, + requests_required_for_capabilities_); + + if (!ui_language_node.isNull()) { + const std::string lang = ui_language_node.asString(); set_active_ui_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_ui_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(ui, "languages")) { + auto ui_languages_node = json_ui_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!ui_languages_node.isNull()) { smart_objects::SmartObject ui_languages_so( smart_objects::SmartType_Array); - Json::Value languages_ui = ui.get("languages", ""); - convert_json_languages_to_obj(languages_ui, ui_languages_so); + ConvertJsonArrayToSoArray( + ui_languages_node, ui_languages_so); set_ui_supported_languages(ui_languages_so); } - if (check_existing_json_member(ui, "displayCapabilities")) { + auto ui_display_capabilities_node = + json_ui_getter.GetJsonMember(hmi_response::display_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_display_capabilities_node.isNull()) { smart_objects::SmartObject display_capabilities_so; - Json::Value display_capabilities = ui.get("displayCapabilities", ""); - formatters::CFormatterJsonBase::jsonValueToObj(display_capabilities, - display_capabilities_so); + formatters::CFormatterJsonBase::jsonValueToObj( + ui_display_capabilities_node, display_capabilities_so); if (display_capabilities_so.keyExists(hmi_response::display_type)) { std::mapsecond; set_hmi_zone_capabilities(hmi_zone_capabilities_so); } - if (check_existing_json_member(ui, "softButtonCapabilities")) { - Json::Value soft_button_capabilities = - ui.get("softButtonCapabilities", ""); + auto ui_soft_button_capabilities_node = + json_ui_getter.GetJsonMember(hmi_response::soft_button_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_soft_button_capabilities_node.isNull()) { smart_objects::SmartObject soft_button_capabilities_so; formatters::CFormatterJsonBase::jsonValueToObj( - soft_button_capabilities, soft_button_capabilities_so); + ui_soft_button_capabilities_node, soft_button_capabilities_so); set_soft_button_capabilities(soft_button_capabilities_so); } - if (check_existing_json_member(ui, "systemCapabilities")) { - Json::Value system_capabilities = ui.get("systemCapabilities", ""); - if (check_existing_json_member(system_capabilities, - "navigationCapability")) { - Json::Value navigation_capability = - system_capabilities.get("navigationCapability", ""); + auto ui_system_capabilities_node = + json_ui_getter.GetJsonMember(strings::system_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_system_capabilities_node.isNull()) { + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::navigation_capability)) { + Json::Value navigation_capability = ui_system_capabilities_node.get( + strings::navigation_capability, ""); smart_objects::SmartObject navigation_capability_so; formatters::CFormatterJsonBase::jsonValueToObj( navigation_capability, navigation_capability_so); @@ -1133,10 +1356,10 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { set_navigation_supported(true); } } - if (check_existing_json_member(system_capabilities, - "phoneCapability")) { + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::phone_capability)) { Json::Value phone_capability = - system_capabilities.get("phoneCapability", ""); + ui_system_capabilities_node.get(strings::phone_capability, ""); smart_objects::SmartObject phone_capability_so; formatters::CFormatterJsonBase::jsonValueToObj(phone_capability, phone_capability_so); @@ -1145,23 +1368,23 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { set_phone_call_supported(true); } } - if (check_existing_json_member(system_capabilities, - "videoStreamingCapability")) { - Json::Value vs_capability = - system_capabilities.get("videoStreamingCapability", ""); + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::video_streaming_capability)) { + Json::Value vs_capability = ui_system_capabilities_node.get( + strings::video_streaming_capability, ""); smart_objects::SmartObject vs_capability_so; formatters::CFormatterJsonBase::jsonValueToObj(vs_capability, vs_capability_so); - if (vs_capability_so.keyExists("supportedFormats")) { + if (vs_capability_so.keyExists(strings::supported_formats)) { smart_objects::SmartObject& supported_format_array = - vs_capability_so["supportedFormats"]; + vs_capability_so[strings::supported_formats]; smart_objects::SmartObject converted_array( smart_objects::SmartType_Array); for (uint32_t i = 0, j = 0; i < supported_format_array.length(); i++) { - if (!supported_format_array[i].keyExists("protocol") || - !supported_format_array[i].keyExists("codec")) { + if (!supported_format_array[i].keyExists(strings::protocol) || + !supported_format_array[i].keyExists(strings::codec)) { continue; } @@ -1169,12 +1392,13 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { hmi_apis::Common_VideoStreamingProtocol::eType>:: const_iterator it_protocol = video_streaming_protocol_enum.find( - supported_format_array[i]["protocol"].asString()); + supported_format_array[i][strings::protocol] + .asString()); std::map:: const_iterator it_codec = video_streaming_codec_enum.find( - supported_format_array[i]["codec"].asString()); + supported_format_array[i][strings::codec].asString()); // format is valid only if both protocol and codec are converted // to enum values successfully @@ -1182,128 +1406,188 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { it_codec != video_streaming_codec_enum.end()) { smart_objects::SmartObject format_so = smart_objects::SmartObject(smart_objects::SmartType_Map); - format_so["protocol"] = it_protocol->second; - format_so["codec"] = it_codec->second; + format_so[strings::protocol] = it_protocol->second; + format_so[strings::codec] = it_codec->second; converted_array[j++] = format_so; } } - vs_capability_so.erase("supportedFormats"); - vs_capability_so["supportedFormats"] = converted_array; + vs_capability_so.erase(strings::supported_formats); + vs_capability_so[strings::supported_formats] = converted_array; } set_video_streaming_capability(vs_capability_so); if (!vs_capability_so.empty()) { set_video_streaming_supported(true); } } - if (check_existing_json_member(system_capabilities, - "remoteControlCapability")) { - Json::Value rc_capability = - system_capabilities.get("remoteControlCapability", ""); - smart_objects::SmartObject rc_capability_so; - formatters::CFormatterJsonBase::jsonValueToObj(rc_capability, - rc_capability_so); - if (rc_capability_so.keyExists("lightControlCapabilities")) { - if (rc_capability_so["lightControlCapabilities"].keyExists( - "supportedLights")) { - auto& lights = rc_capability_so["lightControlCapabilities"] - ["supportedLights"]; - auto it = lights.asArray()->begin(); - for (; it != lights.asArray()->end(); ++it) { - smart_objects::SmartObject& light_name_so = (*it)["name"]; - auto light_name = MessageHelper::CommonLightNameFromString( - light_name_so.asString()); - light_name_so = light_name; - } + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::ui); + } // UI end + + // RC + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::rc)) { + auto rc_json_getter = + GetInterfaceGetter(hmi_interface::rc, json_root_getter); + + auto rc_capabilitity_node = + rc_json_getter.GetJsonMember(strings::rc_capability, + hmi_apis::FunctionID::RC_GetCapabilities, + requests_required_for_capabilities_); + if (!rc_capabilitity_node.isNull()) { + smart_objects::SmartObject rc_capability_so; + formatters::CFormatterJsonBase::jsonValueToObj(rc_capabilitity_node, + rc_capability_so); + if (rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)) { + if (rc_capability_so + [rc_rpc_plugin::strings::klightControlCapabilities] + .keyExists(rc_rpc_plugin::strings::kSupportedLights)) { + auto& lights = rc_capability_so + [rc_rpc_plugin::strings::klightControlCapabilities] + [rc_rpc_plugin::strings::kSupportedLights]; + auto it = lights.asArray()->begin(); + for (; it != lights.asArray()->end(); ++it) { + smart_objects::SmartObject& light_name_so = (*it)[strings::name]; + auto light_name = MessageHelper::CommonLightNameFromString( + light_name_so.asString()); + light_name_so = light_name; } } + } + if (!rc_capability_so.empty()) { + set_rc_supported(true); set_rc_capability(rc_capability_so); - if (!rc_capability_so.empty()) { - set_rc_supported(true); - } } - if (check_existing_json_member(system_capabilities, - "seatLocationCapability")) { - Json::Value seat_location_capability = - system_capabilities.get("seatLocationCapability", ""); - smart_objects::SmartObject seat_location_capability_so; - formatters::CFormatterJsonBase::jsonValueToObj( - seat_location_capability, seat_location_capability_so); + } + + auto seat_location_capabilitiy_node = + rc_json_getter.GetJsonMember(strings::seat_location_capability, + hmi_apis::FunctionID::RC_GetCapabilities, + requests_required_for_capabilities_); + + if (!seat_location_capabilitiy_node.isNull()) { + smart_objects::SmartObject seat_location_capability_so; + formatters::CFormatterJsonBase::jsonValueToObj( + seat_location_capabilitiy_node, seat_location_capability_so); + + if (!seat_location_capability_so.empty()) { + set_rc_supported(true); set_seat_location_capability(seat_location_capability_so); } } - } // UI end + } else { + AddRequiredRequestsForCapabilities(hmi_interface::rc); + } + // RC end // VR - if (check_existing_json_member(root_json, "VR")) { - Json::Value vr = root_json.get("VR", ""); - if (check_existing_json_member(vr, "language")) { - const std::string lang = vr.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::vr)) { + auto json_vr_getter = + GetInterfaceGetter(hmi_interface::vr, json_root_getter); + + auto vr_language_node = + json_vr_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::VR_GetLanguage, + requests_required_for_capabilities_); + if (!vr_language_node.isNull()) { + const std::string lang = vr_language_node.asString(); set_active_vr_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_vr_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(vr, "languages")) { - Json::Value languages_vr = vr.get("languages", ""); + auto vr_languages_node = json_vr_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!vr_languages_node.isNull()) { smart_objects::SmartObject vr_languages_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - convert_json_languages_to_obj(languages_vr, vr_languages_so); + ConvertJsonArrayToSoArray( + vr_languages_node, vr_languages_so); set_vr_supported_languages(vr_languages_so); } - if (check_existing_json_member(vr, "capabilities")) { - Json::Value capabilities = vr.get("capabilities", ""); + auto vr_capabilities_node = + json_vr_getter.GetJsonMember(strings::vr_capabilities, + hmi_apis::FunctionID::VR_GetCapabilities, + requests_required_for_capabilities_); + if (!vr_capabilities_node.isNull()) { smart_objects::SmartObject vr_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < capabilities.size(); ++i) { - vr_capabilities_so[i] = - vr_enum_capabilities.find(capabilities[i].asString())->second; - } + ConvertJsonArrayToSoArray( + vr_capabilities_node, vr_capabilities_so); set_vr_capabilities(vr_capabilities_so); } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::vr); } // VR end // TTS - if (check_existing_json_member(root_json, "TTS")) { - Json::Value tts = root_json.get("TTS", ""); - - if (check_existing_json_member(tts, "language")) { - const std::string lang = tts.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::tts)) { + auto json_tts_getter = + GetInterfaceGetter(hmi_interface::tts, json_root_getter); + + auto tts_language_node = + json_tts_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::TTS_GetLanguage, + requests_required_for_capabilities_); + if (!tts_language_node.isNull()) { + const std::string lang = tts_language_node.asString(); set_active_tts_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_tts_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(tts, "languages")) { - Json::Value languages_tts = tts.get("languages", ""); + auto tts_languages_node = json_tts_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!tts_languages_node.isNull()) { smart_objects::SmartObject tts_languages_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - convert_json_languages_to_obj(languages_tts, tts_languages_so); + ConvertJsonArrayToSoArray( + tts_languages_node, tts_languages_so); set_tts_supported_languages(tts_languages_so); } - if (check_existing_json_member(tts, "capabilities")) { - Json::Value capabilities = tts.get("capabilities", ""); + auto tts_speech_capabilities_node = json_tts_getter.GetJsonMember( + hmi_response::speech_capabilities, + hmi_apis::FunctionID::TTS_GetCapabilities, + requests_required_for_capabilities_); + if (!tts_speech_capabilities_node.isNull()) { smart_objects::SmartObject tts_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < capabilities.size(); ++i) { - tts_capabilities_so[i] = - tts_enum_capabilities.find(capabilities[i].asString())->second; - } + ConvertJsonArrayToSoArray( + tts_speech_capabilities_node, tts_capabilities_so); set_speech_capabilities(tts_capabilities_so); } + + auto tts_prerecorded_speech_capabilities_node = + json_tts_getter.GetJsonMember( + hmi_response::prerecorded_speech_capabilities, + hmi_apis::FunctionID::TTS_GetCapabilities, + requests_required_for_capabilities_); + if (!tts_prerecorded_speech_capabilities_node.isNull()) { + smart_objects::SmartObject tts_capabilities_so = + smart_objects::SmartObject(smart_objects::SmartType_Array); + ConvertJsonArrayToSoArray( + tts_prerecorded_speech_capabilities_node, tts_capabilities_so); + set_prerecorded_speech(tts_capabilities_so); + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::tts); } // TTS end // Buttons - if (check_existing_json_member(root_json, "Buttons")) { - Json::Value buttons = root_json.get("Buttons", ""); - if (check_existing_json_member(buttons, "capabilities")) { - Json::Value bt_capabilities = buttons.get("capabilities", ""); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::buttons)) { + auto json_buttons_getter = + GetInterfaceGetter(hmi_interface::buttons, json_root_getter); + + auto buttons_capabilities_node = json_buttons_getter.GetJsonMember( + hmi_response::capabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + requests_required_for_capabilities_); + if (!buttons_capabilities_node.isNull()) { smart_objects::SmartObject buttons_capabilities_so; - formatters::CFormatterJsonBase::jsonValueToObj(bt_capabilities, - buttons_capabilities_so); + formatters::CFormatterJsonBase::jsonValueToObj( + buttons_capabilities_node, buttons_capabilities_so); for (uint32_t i = 0; i < buttons_capabilities_so.length(); ++i) { if ((buttons_capabilities_so[i]).keyExists(strings::name)) { @@ -1319,22 +1603,39 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { } set_button_capabilities(buttons_capabilities_so); } - if (check_existing_json_member(buttons, "presetBankCapabilities")) { - Json::Value presetBank = buttons.get("presetBankCapabilities", ""); + + auto buttons_preset_bank_capabilities_node = + json_buttons_getter.GetMainJsonMember( + hmi_response::preset_bank_capabilities); + if (!buttons_preset_bank_capabilities_node.isNull()) { smart_objects::SmartObject preset_bank_so; - formatters::CFormatterJsonBase::jsonValueToObj(presetBank, - preset_bank_so); + formatters::CFormatterJsonBase::jsonValueToObj( + buttons_preset_bank_capabilities_node, preset_bank_so); set_preset_bank_capabilities(preset_bank_so); } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::buttons); } // Buttons end // VehicleType - if (check_existing_json_member(root_json, "VehicleInfo")) { - Json::Value vehicle_info = root_json.get("VehicleInfo", ""); - smart_objects::SmartObject vehicle_type_so; - formatters::CFormatterJsonBase::jsonValueToObj(vehicle_info, - vehicle_type_so); - set_vehicle_type(vehicle_type_so); + + if (json_root_getter.IsInterfaceJsonMemberExists( + hmi_interface::vehicle_info)) { + auto json_vehicle_info_getter = + GetInterfaceGetter(hmi_interface::vehicle_info, json_root_getter); + + auto vehicle_type_node = json_vehicle_info_getter.GetJsonMember( + hmi_response::vehicle_type, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType, + requests_required_for_capabilities_); + if (!vehicle_type_node.isNull()) { + smart_objects::SmartObject vehicle_type_so; + formatters::CFormatterJsonBase::jsonValueToObj(vehicle_type_node, + vehicle_type_so); + set_vehicle_type(vehicle_type_so); + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::vehicle_info); } // VehicleType end } catch (...) { return false; @@ -1342,6 +1643,534 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { return true; } +hmi_apis::Common_Language::eType +HMICapabilitiesImpl::GetActiveLanguageForInterface( + const std::string& interface_name) const { + LOG4CXX_AUTO_TRACE(logger_); + if (hmi_interface::ui == interface_name) { + return active_ui_language(); + } + if (hmi_interface::vr == interface_name) { + return active_vr_language(); + } + if (hmi_interface::tts == interface_name) { + return active_tts_language(); + } + return hmi_apis::Common_Language::INVALID_ENUM; +} + +void HMICapabilitiesImpl::UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) { + LOG4CXX_AUTO_TRACE(logger_); + if (app_mngr_.IsHMICooperating()) { + LOG4CXX_DEBUG(logger_, + "Remove from default initialized capabilities skipped, " + "because hmi_cooperating equal true already"); + return; + } + + RemoveFromRequestsRequiredForCapabilities(requested_interface); + if (requests_required_for_capabilities_.empty()) { + app_mngr_.SetHMICooperating(true); + } +} + +void HMICapabilitiesImpl::OnSoftwareVersionReceived( + const std::string& ccpu_version) { + LOG4CXX_AUTO_TRACE(logger_); + + if (ccpu_version == ccpu_version_) { + LOG4CXX_DEBUG(logger_, "Software version not changed"); + if (requests_required_for_capabilities_.empty()) { + app_mngr_.SetHMICooperating(true); + } + app_mngr_.RequestForInterfacesAvailability(); + return; + } + + LOG4CXX_DEBUG(logger_, "Software version changed"); + set_ccpu_version(ccpu_version); + UpdateCachedCapabilities(); +} + +void HMICapabilitiesImpl::UpdateCachedCapabilities() { + LOG4CXX_AUTO_TRACE(logger_); + + DeleteCachedCapabilitiesFile(); + + if (!LoadCapabilitiesFromFile()) { + LOG4CXX_ERROR(logger_, "file hmi_capabilities.json was not loaded"); + } + + app_mngr_.RequestForInterfacesAvailability(); +} + +bool HMICapabilitiesImpl::AllFieldsSaved( + const Json::Value& root_node, + const std::string& interface_name, + const std::vector& sections_to_check) const { + LOG4CXX_AUTO_TRACE(logger_); + if (!JsonIsMemberSafe(root_node, interface_name.c_str())) { + LOG4CXX_DEBUG(logger_, + interface_name + << " interface is not found. All fields should be saved"); + return false; + } + + const auto& interface_node = root_node.get(interface_name, Json::Value::null); + for (auto it = sections_to_check.begin(); it != sections_to_check.end(); + ++it) { + const std::string section = (*it).c_str(); + if (!JsonIsMemberSafe(interface_node, section.c_str())) { + LOG4CXX_DEBUG(logger_, + "Field " << *it << " should be saved into the file"); + return false; + } + + if (hmi_response::language == section) { + const auto active_language = + GetActiveLanguageForInterface(interface_name); + const auto json_language = interface_node[hmi_response::language]; + + if (active_language != + MessageHelper::CommonLanguageFromString(json_language.asString())) { + LOG4CXX_DEBUG(logger_, + "Active " << interface_name + << " language is not the same as the persisted " + "one. Field should be overwritten"); + return false; + } + } + } + + return true; +} + +void HMICapabilitiesImpl::RemoveFromRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) { + LOG4CXX_AUTO_TRACE(logger_); + + auto it = find(requests_required_for_capabilities_.begin(), + requests_required_for_capabilities_.end(), + requested_interface); + if (it != requests_required_for_capabilities_.end()) { + requests_required_for_capabilities_.erase(it); + LOG4CXX_DEBUG(logger_, + "Wait for " << requests_required_for_capabilities_.size() + << " responses"); + } +} + +void HMICapabilitiesImpl::PrepareUiJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject capability(smart_objects::SmartType_Map); + auto system_capabilities = std::make_shared( + capability[strings::system_capabilities]); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::hmi_zone_capabilities) { + save_hmi_capability_field_to_json(hmi_response::hmi_zone_capabilities, + schema, + hmi_zone_capabilities(), + out_node); + } + + else if (section_to_update == hmi_response::soft_button_capabilities) { + save_hmi_capability_field_to_json(hmi_response::soft_button_capabilities, + schema, + soft_button_capabilities(), + out_node); + } + + else if (section_to_update == strings::audio_pass_thru_capabilities) { + smart_objects::SmartObjectSPtr audio_pass_thru_capabilities_so = + audio_pass_thru_capabilities(); + + for (size_t i = 0; i < audio_pass_thru_capabilities_so->length(); ++i) { + const smart_objects::SmartObject& element = + (*audio_pass_thru_capabilities_so)[i]; + const auto audio_pass_thru_capabilities = + std::make_shared(element); + Json::Value out_audio_pass_thru; + save_hmi_capability_field_to_json(strings::audio_pass_thru_capabilities, + schema, + audio_pass_thru_capabilities, + out_audio_pass_thru); + out_node[strings::audio_pass_thru_capabilities][Json::ArrayIndex(i)] = + out_audio_pass_thru[strings::audio_pass_thru_capabilities]; + } + } + + else if (section_to_update == strings::navigation) { + out_node[strings::hmi_capabilities][strings::navigation] = + navigation_supported(); + } + + else if (section_to_update == strings::phone_call) { + out_node[strings::hmi_capabilities][strings::phone_call] = + phone_call_supported(); + } + + else if (section_to_update == strings::video_streaming) { + out_node[strings::hmi_capabilities][strings::video_streaming] = + video_streaming_supported(); + } + + else if (section_to_update == strings::navigation_capability) { + const auto navigation_capability_so = navigation_capability(); + if (navigation_capability_so) { + (*system_capabilities)[strings::navigation_capability] = + *navigation_capability_so; + } + } + + else if (section_to_update == strings::phone_capability) { + const auto phone_capability_so = phone_capability(); + if (phone_capability_so) { + (*system_capabilities)[strings::phone_capability] = + *phone_capability_so; + } + } + + else if (section_to_update == strings::video_streaming_capability) { + const auto video_streaming_capability_so = video_streaming_capability(); + + if (video_streaming_capability_so) { + (*system_capabilities)[strings::video_streaming_capability] = + *video_streaming_capability_so; + } + } + + else if (section_to_update == strings::display_capabilities) { + const auto display_capabilities_so = display_capabilities(); + + if (display_capabilities_so) { + save_hmi_capability_field_to_json(strings::display_capabilities, + schema, + display_capabilities_so, + out_node); + } + } + + else if (section_to_update == strings::pcm_stream_capabilities) { + save_hmi_capability_field_to_json(strings::pcm_stream_capabilities, + schema, + pcm_stream_capabilities(), + out_node); + } + + else if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_ui_language()); + } + + else if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, ui_supported_languages(), out_node); + } + } + + if (!system_capabilities->empty()) { + save_hmi_capability_field_to_json( + strings::system_capabilities, schema, system_capabilities, out_node); + } +} + +void HMICapabilitiesImpl::PrepareVrJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_vr_language()); + } + + if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, vr_supported_languages(), out_node); + } + + if (section_to_update == strings::vr_capabilities) { + save_hmi_capability_field_to_json( + strings::vr_capabilities, schema, vr_capabilities(), out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareTtsJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_tts_language()); + } + + if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, tts_supported_languages(), out_node); + } + + if (section_to_update == hmi_response::speech_capabilities) { + save_hmi_capability_field_to_json(hmi_response::speech_capabilities, + schema, + speech_capabilities(), + out_node); + } + + if (section_to_update == hmi_response::prerecorded_speech_capabilities) { + save_hmi_capability_field_to_json( + hmi_response::prerecorded_speech_capabilities, + schema, + prerecorded_speech(), + out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareButtonsJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::button_capabilities) { + save_hmi_capability_field_to_json( + hmi_response::capabilities, schema, button_capabilities(), out_node); + } + + if (section_to_update == hmi_response::preset_bank_capabilities) { + save_hmi_capability_field_to_json(hmi_response::preset_bank_capabilities, + schema, + preset_bank_capabilities(), + out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareVehicleInfoJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + if (helpers::in_range(sections_to_update, hmi_response::vehicle_type)) { + save_hmi_capability_field_to_json( + hmi_response::vehicle_type, schema, vehicle_type(), out_node); + } +} + +void HMICapabilitiesImpl::PrepareRCJsonValueForSaving( + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == strings::rc_capability) { + save_hmi_capability_field_to_json( + strings::rc_capability, schema, rc_capability(), out_node); + } + + if (section_to_update == strings::seat_location_capability) { + save_hmi_capability_field_to_json(strings::seat_location_capability, + schema, + seat_location_capability(), + out_node); + } + } +} + +void HMICapabilitiesImpl::AddRequiredRequestsForCapabilities( + const std::string& interface_name) { + LOG4CXX_DEBUG(logger_, "Add request IDs for interface: " << interface_name); + + if (interface_name == hmi_interface::ui) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetCapabilities); + } + + else if (interface_name == hmi_interface::rc) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::RC_GetCapabilities); + } + + else if (interface_name == hmi_interface::vr) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetCapabilities); + } + + else if (interface_name == hmi_interface::tts) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetCapabilities); + } + + else if (interface_name == hmi_interface::buttons) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::Buttons_GetCapabilities); + } + + else if (interface_name == hmi_interface::vehicle_info) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); + } +} + +void HMICapabilitiesImpl::PrepareJsonValueForSaving( + const char* interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_root_node) const { + LOG4CXX_DEBUG(logger_, + "Prepare " << interface_name << " sections for saving"); + + if (out_root_node.isNull()) { + out_root_node = Json::Value(Json::objectValue); + } + + if (!out_root_node.isMember(interface_name)) { + out_root_node[interface_name] = Json::Value(Json::objectValue); + } + + Json::Value& interface_node = out_root_node[interface_name]; + if (strcmp(interface_name, hmi_interface::ui) == 0) { + PrepareUiJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::vr) == 0) { + PrepareVrJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::tts) == 0) { + PrepareTtsJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::buttons) == 0) { + PrepareButtonsJsonValueForSaving( + sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::vehicle_info) == 0) { + PrepareVehicleInfoJsonValueForSaving( + sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::rc) == 0) { + PrepareRCJsonValueForSaving(sections_to_update, schema, interface_node); + } +} + +bool HMICapabilitiesImpl::SaveCachedCapabilitiesToFile( + const std::string& interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema) { + LOG4CXX_AUTO_TRACE(logger_); + + if (sections_to_update.empty()) { + LOG4CXX_DEBUG(logger_, + "There is no one section to update in the cache file"); + return true; + } + + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + if (cache_file_name.empty()) { + LOG4CXX_DEBUG(logger_, + "Cache file name is not specified. No need to save cache"); + return true; + } + + Json::Value root_node; + if (file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, "Cache file exists. Check for it's content"); + + std::string file_content; + if (!file_system::ReadFile(cache_file_name, file_content)) { + LOG4CXX_ERROR(logger_, "Failed to read file content"); + return false; + } + + Json::CharReaderBuilder builder; + const std::unique_ptr reader(builder.newCharReader()); + if (!reader->parse(file_content.c_str(), + file_content.c_str() + file_content.length(), + &root_node, + NULL)) { + LOG4CXX_ERROR(logger_, "Can't parse the file. Skipping"); + return false; + } + + if (AllFieldsSaved(root_node, interface_name, sections_to_update)) { + LOG4CXX_DEBUG( + logger_, + "All " << interface_name + << " fields are present in the file. No need to update"); + return true; + } + + LOG4CXX_DEBUG(logger_, "Some fields in the cache file should be updated"); + } + + PrepareJsonValueForSaving( + interface_name.c_str(), sections_to_update, schema, root_node); + + LOG4CXX_DEBUG(logger_, "Saving cache to file: " << cache_file_name); + const std::string content_to_save = root_node.toStyledString(); + const std::vector binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + + return file_system::Write(cache_file_name, binary_data_to_save); +} + +bool HMICapabilitiesImpl::DeleteCachedCapabilitiesFile() const { + LOG4CXX_AUTO_TRACE(logger_); + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + if (cache_file_name.empty()) { + LOG4CXX_DEBUG(logger_, + "Cache file name is not specified. Nothing to delete"); + return false; + } + + if (!file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, "Cache file does not exist"); + return false; + } + + if (!file_system::DeleteFile(cache_file_name)) { + LOG4CXX_ERROR(logger_, "Failed to delete cache file"); + return false; + } + return true; +} + +bool HMICapabilitiesImpl::IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType function_id) const { + return helpers::in_range(requests_required_for_capabilities_, function_id); +} + void HMICapabilitiesImpl::set_ccpu_version(const std::string& ccpu_version) { ccpu_version_ = ccpu_version; } @@ -1350,11 +2179,6 @@ const std::string& HMICapabilitiesImpl::ccpu_version() const { return ccpu_version_; } -bool HMICapabilitiesImpl::check_existing_json_member( - const Json::Value& json_member, const char* name_of_member) const { - return json_member.isMember(name_of_member); -} - void HMICapabilitiesImpl::convert_json_languages_to_obj( const Json::Value& json_languages, smart_objects::SmartObject& languages) const { @@ -1367,18 +2191,18 @@ void HMICapabilitiesImpl::convert_json_languages_to_obj( void HMICapabilitiesImpl::convert_audio_capability_to_obj( const Json::Value& capability, smart_objects::SmartObject& output_so) const { - if (check_existing_json_member(capability, "samplingRate")) { + if (JsonIsMemberSafe(capability, "samplingRate")) { output_so[strings::sampling_rate] = sampling_rate_enum.find(capability.get("samplingRate", "").asString()) ->second; } - if (check_existing_json_member(capability, "bitsPerSample")) { + if (JsonIsMemberSafe(capability, "bitsPerSample")) { output_so[strings::bits_per_sample] = bit_per_sample_enum .find(capability.get("bitsPerSample", "").asString()) ->second; } - if (check_existing_json_member(capability, "audioType")) { + if (JsonIsMemberSafe(capability, "audioType")) { output_so[strings::audio_type] = audio_type_enum.find(capability.get("audioType", "").asString()) ->second; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 646d523cf4..4992bd96ca 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1018,6 +1018,11 @@ void PolicyHandler::OnSystemInfoChanged(const std::string& language) { policy_manager_->SetSystemLanguage(language); } +void PolicyHandler::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + policy_manager_->SetPreloadedPtFlag(is_preloaded); +} + void PolicyHandler::OnGetSystemInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { @@ -1026,6 +1031,11 @@ void PolicyHandler::OnGetSystemInfo(const std::string& ccpu_version, policy_manager_->SetSystemInfo(ccpu_version, wers_country_code, language); } +std::string PolicyHandler::GetCCPUVersionFromPT() const { + LOG4CXX_AUTO_TRACE(logger_); + return policy_manager_->GetCCPUVersionFromPT(); +} + void PolicyHandler::OnVIIsReady() { LOG4CXX_AUTO_TRACE(logger_); const uint32_t correlation_id = diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index fe0f878e6c..e0204fd6c7 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -438,6 +438,19 @@ const char* const x = "x"; const char* const y = "y"; } // namespace strings +namespace hmi_interface { +const char* basic_communication = "BasicCommunication"; +const char* buttons = "Buttons"; +const char* navigation = "Navigation"; +const char* sdl = "SDL"; +const char* tts = "TTS"; +const char* ui = "UI"; +const char* vr = "VR"; +const char* rc = "RC"; +const char* vehicle_info = "VehicleInfo"; +const char* app_service = "AppService"; +} // namespace hmi_interface + namespace json { const char* appId = "appId"; const char* name = "name"; @@ -547,6 +560,7 @@ const char* capabilities = "capabilities"; const char* speech_capabilities = "speechCapabilities"; const char* prerecorded_speech_capabilities = "prerecordedSpeechCapabilities"; const char* preset_bank_capabilities = "presetBankCapabilities"; +const char* on_screen_presets_available = "onScreenPresetsAvailable"; const char* allowed = "allowed"; const char* vehicle_type = "vehicleType"; const char* did_result = "didResult"; diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index afc39b9fdd..c9c9a80391 100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -47,6 +47,7 @@ include_directories( ${COMPONENTS_DIR}/application_manager/test/include/ ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include/ ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include/ + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/include/ ${BSON_INCLUDE_DIRECTORY} ) @@ -158,7 +159,7 @@ set(ResumptionData_SOURCES ${AM_TEST_DIR}/mock_message_helper.cc ) -file(COPY hmi_capabilities.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_SOURCE_DIR}/src/appMain/hmi_capabilities.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_sc1.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_sc2.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_old_apt.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 687959263f..d19cbbad22 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -269,6 +269,17 @@ class ApplicationManagerImplTest ASSERT_TRUE(mock_app_ptr_.get()); } + void SetExpectationForCreateModuleInfoSO( + const hmi_apis::FunctionID::eType function_id) { + smart_objects::SmartObject sm_object(smart_objects::SmartType_Map); + sm_object[strings::params][strings::function_id] = + static_cast(function_id); + auto sptr = std::make_shared(sm_object); + + ON_CALL(*mock_message_helper_, CreateModuleInfoSO(function_id, _)) + .WillByDefault(Return(sptr)); + } + application_manager::commands::MessageSharedPtr CreateCloseAppMessage() { using namespace application_manager; @@ -351,6 +362,13 @@ class ApplicationManagerImplTest mock_statistics_manager_; }; +MATCHER_P(HMIFunctionIDIs, result_code, "") { + return result_code == static_cast( + (*arg)[application_manager::strings::params] + [application_manager::strings::function_id] + .asInt()); +} + INSTANTIATE_TEST_CASE_P( ProcessServiceStatusUpdate_REQUEST_ACCEPTED, ApplicationManagerImplTest, @@ -2038,6 +2056,26 @@ TEST_F(ApplicationManagerImplTest, AddAndRemoveQueryAppDevice_SUCCESS) { EXPECT_FALSE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); } +TEST_F( + ApplicationManagerImplTest, + RequestForInterfacesAvailability_AllRequestsWillBeSuccessfullyRequested) { + std::vector expected_requests{ + hmi_apis::FunctionID::VehicleInfo_IsReady, + hmi_apis::FunctionID::VR_IsReady, + hmi_apis::FunctionID::TTS_IsReady, + hmi_apis::FunctionID::UI_IsReady, + hmi_apis::FunctionID::RC_IsReady}; + + for (auto request : expected_requests) { + SetExpectationForCreateModuleInfoSO(request); + EXPECT_CALL(*mock_rpc_service_, + ManageHMICommand(HMIFunctionIDIs(request), + commands::Command::SOURCE_HMI)); + } + + app_manager_impl_->RequestForInterfacesAvailability(); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/hmi_capabilities.json b/src/components/application_manager/test/hmi_capabilities.json deleted file mode 100644 index afa5fa6056..0000000000 --- a/src/components/application_manager/test/hmi_capabilities.json +++ /dev/null @@ -1,731 +0,0 @@ -{ - "UI": { - "language":"EN_US", - "languages":[ - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "AR_SA", - "KO_KR", - "PT_BR", - "CS_CZ", - "DA_DK", - "NO_NO", - "NL_BE", - "EL_GR", - "HU_HU", - "FI_FI", - "SK_SK", - "EN_IN", - "TH_TH", - "EN_SA", - "HE_IL", - "RO_RO", - "UK_UA", - "ID_ID", - "VI_VN", - "MS_MY", - "HI_IN" - ], - "displayCapabilities": { - "displayType": "GEN2_8_DMA", - "displayName": "GENERIC_DISPLAY", - "textFields": [ - { - "name": "mainField1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField3", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField4", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "statusBar", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mediaClock", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mediaTrack", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText3", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "scrollableMessageBody", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "initialInteractionText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "ETA", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "totalDistance", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "audioPassThruDisplayText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "audioPassThruDisplayText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "sliderHeader", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "sliderFooter", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "notificationText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "menuName", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "secondaryText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "tertiaryText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "timeToDestination", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "turnText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "menuTitle", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - } - ], - "imageFields": [ - { - "name": "softButtonImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "choiceImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "choiceSecondaryImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "menuIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "cmdIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "appIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "graphic", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "secondaryGraphic", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "locationImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - } - - ], - "mediaClockFormats": [ - "CLOCK1", - "CLOCK2", - "CLOCK3", - "CLOCKTEXT1", - "CLOCKTEXT2", - "CLOCKTEXT3", - "CLOCKTEXT4" - ], - "graphicSupported": true, - "templatesAvailable": [ - - "DEFAULT", - "MEDIA", - "NON-MEDIA", - "ONSCREEN_PRESETS", - "NAV_FULLSCREEN_MAP", - "NAV_KEYBOARD", - "GRAPHIC_WITH_TEXT", - "TEXT_WITH_GRAPHIC", - "TILES_ONLY", - "TEXTBUTTONS_ONLY", - "GRAPHIC_WITH_TILES", - "TILES_WITH_GRAPHIC", - "GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS", - "TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC", - "GRAPHIC_WITH_TEXTBUTTONS", - "TEXTBUTTONS_WITH_GRAPHIC", - "LARGE_GRAPHIC_WITH_SOFTBUTTONS", - "DOUBLE_GRAPHIC_WITH_SOFTBUTTONS", - "LARGE_GRAPHIC_ONLY" - ], - "screenParams": { - "resolution": { - "resolutionWidth": 800, - "resolutionHeight": 350 - }, - "touchEventAvailable": { - "pressAvailable": true, - "multiTouchAvailable": false, - "doublePressAvailable": false - } - }, - "numCustomPresetsAvailable": 8, - "imageCapabilities": [ - "DYNAMIC", - "STATIC" - ] - }, - "audioPassThruCapabilities": [{ - "samplingRate": "44KHZ", - "bitsPerSample": "RATE_8_BIT", - "audioType": "PCM" - }], - "pcmStreamCapabilities": { - "samplingRate": "16KHZ", - "bitsPerSample": "RATE_16_BIT", - "audioType": "PCM" - }, - "hmiZoneCapabilities": "FRONT", - "softButtonCapabilities": [ - { - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true, - "imageSupported": true - } - ], - "systemCapabilities": { - "navigationCapability": { - "sendLocationEnabled": true, - "getWayPointsEnabled": true - }, - "phoneCapability": { - "dialNumberEnabled": true - }, - - "remoteControlCapability":{ - "climateControlCapabilities": [ - { - "moduleName": "primary_climate", - "fanSpeedAvailable": true, - "desiredTemperatureAvailable": true, - "acEnableAvailable": true, - "acMaxEnableAvailable": true, - "circulateAirEnableAvailable": true, - "autoModeEnableAvailable": true, - "dualModeEnableAvailable": true, - "defrostZoneAvailable": true, - "ventilationModeAvailable": true, - "defrostZone": [ - "FRONT", - "REAR", - "ALL", - "NONE" - ], - "ventilationMode": [ - "UPPER", - "LOWER", - "BOTH", - "NONE" - ] - } - ], - "radioControlCapabilities": [ - { - "moduleName": "radio", - "radioEnableAvailable": true, - "radioBandAvailable": true, - "radioFrequencyAvailable": true, - "hdChannelAvailable": true, - "rdsDataAvailable": true, - "availableHDsAvailable": true, - "stateAvailable": true, - "signalStrengthAvailable": true, - "signalChangeThresholdAvailable": true - } - ], - "buttonCapabilities": [ - { - "name": "AC_MAX", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "AC", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "RECIRCULATE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "FAN_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "FAN_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "TEMP_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "TEMP_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST_MAX", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST_REAR", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "UPPER_VENT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "LOWER_VENT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "VOLUME_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "VOLUME_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "EJECT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "SOURCE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "SHUFFLE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "REPEAT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - } - ] - }, - "videoStreamingCapability": { - "preferredResolution": { - "resolutionWidth": 800, - "resolutionHeight": 350 - }, - "maxBitrate": 10000, - "supportedFormats": [ - { - "protocol": "RAW", - "codec": "H264" - }, - { - "protocol": "RTP", - "codec": "Theora" - } - ], - "hapticSpatialDataSupported": true - } - } - }, - "VR": { - "capabilities": [ - "TEXT" - ], - "language": "ES_MX", - "languages": [ - "AR_SA", - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "KO_KR", - "PT_BR", - "CS_CZ", - "DA_DK", - "NO_NO" - ] - }, - "TTS": { - "capabilities": [ - "TEXT" - ], - "language": "DE_DE", - "languages": [ - "DA_DK", - "CS_CZ", - "KO_KR", - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "AR_SA", - "PT_BR", - "NO_NO" - ] - }, - "Buttons": { - "capabilities": [ - { - "name": "PRESET_0", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_1", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_2", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_3", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_4", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_5", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_6", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_7", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_8", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_9", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "OK", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PLAY_PAUSE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "SEEKLEFT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "SEEKRIGHT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "TUNEUP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "TUNEDOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - } - ], - "presetBankCapabilities": { - "onScreenPresetsAvailable": true - } - }, - "VehicleInfo": { - "make": "Ford", - "model": "Fiesta", - "modelYear": "2013", - "trim": "SE" - }, - "SyncMessageVersion": { - "majorVersion": 3, - "minorVersion": 0 - } -} diff --git a/src/components/application_manager/test/hmi_capabilities_sc2.json b/src/components/application_manager/test/hmi_capabilities_sc2.json index a8578f04f5..318fcf7a3e 100644 --- a/src/components/application_manager/test/hmi_capabilities_sc2.json +++ b/src/components/application_manager/test/hmi_capabilities_sc2.json @@ -1,5 +1,11 @@ { "UI": { + "language": "EN_US", + "languages": [ + "EN_US", + "ES_MX", + "FR_CA" + ], "systemCapabilities": { "navigationCapability": { "sendLocationEnabled": true, diff --git a/src/components/application_manager/test/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 6234830f50..73e86fc7a7 100644 --- a/src/components/application_manager/test/hmi_capabilities_test.cc +++ b/src/components/application_manager/test/hmi_capabilities_test.cc @@ -33,7 +33,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/hmi_capabilities_impl.h" + +#include +#include #include +#include #include "application_manager/hmi_capabilities.h" #include "application_manager/mock_message_helper.h" @@ -42,81 +47,57 @@ #include "smart_objects/enum_schema_item.h" #include "smart_objects/smart_object.h" -#include "application_manager/hmi_capabilities_for_testing.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_application_manager_settings.h" #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_rpc_service.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/state_controller.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "resumption/last_state_impl.h" #include "resumption/last_state_wrapper_impl.h" #include "utils/file_system.h" +#include "utils/jsoncpp_reader_wrapper.h" namespace test { namespace components { namespace application_manager_test { +namespace { +const std::string kAppInfoDataFile = "./app_info_data"; +const std::string kAppStorageFolder = "app_storage_folder"; +const std::string kAppInfoStorage = "app_info_storage"; +const std::string kHmiCapabilitiesDefaultFile = "hmi_capabilities.json"; +const std::string kHmiCapabilitiesCacheFile = "hmi_capabilities_cache.json"; +const uint32_t kEqualizerMaxChanelId = 10; +} // namespace + using ::testing::_; -using ::testing::AtLeast; -using ::testing::InSequence; using ::testing::Invoke; +using ::testing::NiceMock; using ::testing::Return; using ::testing::ReturnRef; using namespace application_manager; -class HMICapabilitiesTest : public ::testing::Test { - protected: - HMICapabilitiesTest() - : last_state_wrapper_(std::make_shared( - std::make_shared("app_storage_folder", - "app_info_storage"))) - , file_name_("hmi_capabilities.json") {} - virtual void SetUp() OVERRIDE { - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings_)); - EXPECT_CALL(mock_application_manager_settings_, - hmi_capabilities_file_name()) - .WillOnce(ReturnRef(file_name_)); - EXPECT_CALL(mock_event_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_event_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings_, launch_hmi()) - .WillOnce(Return(false)); - hmi_capabilities_test = - std::make_shared(app_mngr_); - hmi_capabilities_test->Init(last_state_wrapper_); - } +typedef std::map + LanguageCStringToEnumMap; - void TearDown() OVERRIDE { - hmi_capabilities_test.reset(); - } - static void TearDownTestCase() { - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - } +typedef std::map + LightNameCStringToEnumMap; - void SetCooperating(); - MockApplicationManager app_mngr_; - event_engine_test::MockEventDispatcher mock_event_dispatcher; - resumption::LastStateWrapperPtr last_state_wrapper_; - MockApplicationManagerSettings mock_application_manager_settings_; - std::shared_ptr hmi_capabilities_test; - const std::string file_name_; - application_manager_test::MockRPCService mock_rpc_service_; -}; +static LanguageCStringToEnumMap languages_map; +static LightNameCStringToEnumMap light_names_map; -const char* const cstring_values_[] = { - "EN_US", "ES_MX", "FR_CA", "DE_DE", "ES_ES", "EN_GB", "RU_RU", "TR_TR", - "PL_PL", "FR_FR", "IT_IT", "SV_SE", "PT_PT", "NL_NL", "EN_AU", "ZH_CN", - "ZH_TW", "JA_JP", "AR_SA", "KO_KR", "PT_BR", "CS_CZ", "DA_DK", "NO_NO", - "NL_BE", "EL_GR", "HU_HU", "FI_FI", "SK_SK", "EN_IN", "TH_TH", "EN_SA", - "HE_IL", "RO_RO", "UK_UA", "ID_ID", "VI_VN", "MS_MY", "HI_IN"}; +const std::vector language_string_values{ + {"EN-US"}, {"ES-MX"}, {"FR-CA"}, {"DE-DE"}, {"ES-ES"}, {"EN-GB"}, {"RU-RU"}, + {"TR-TR"}, {"PL-PL"}, {"FR-FR"}, {"IT-IT"}, {"SV-SE"}, {"PT-PT"}, {"NL-NL"}, + {"EN-AU"}, {"ZH-CN"}, {"ZH-TW"}, {"JA-JP"}, {"AR-SA"}, {"KO-KR"}, {"PT-BR"}, + {"CS-CZ"}, {"DA-DK"}, {"NO-NO"}, {"NL-BE"}, {"EL-GR"}, {"HU-HU"}, {"FI-FI"}, + {"SK-SK"}, {"EN-IN"}, {"TH-TH"}, {"EN-SA"}, {"HE-IL"}, {"RO-RO"}, {"UK-UA"}, + {"ID-ID"}, {"VI-VN"}, {"MS-MY"}, {"HI-IN"}}; -const hmi_apis::Common_Language::eType enum_values_[] = { +const std::vector language_enum_values{ hmi_apis::Common_Language::EN_US, hmi_apis::Common_Language::ES_MX, hmi_apis::Common_Language::FR_CA, hmi_apis::Common_Language::DE_DE, hmi_apis::Common_Language::ES_ES, hmi_apis::Common_Language::EN_GB, @@ -138,142 +119,338 @@ const hmi_apis::Common_Language::eType enum_values_[] = { hmi_apis::Common_Language::VI_VN, hmi_apis::Common_Language::MS_MY, hmi_apis::Common_Language::HI_IN}; -struct CStringComparator { - bool operator()(const char* a, const char* b) { - return strcmp(a, b) < 0; +const std::vector light_name_enum_values{ + hmi_apis::Common_LightName::eType::FRONT_LEFT_HIGH_BEAM, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_HIGH_BEAM, + hmi_apis::Common_LightName::eType::FRONT_LEFT_LOW_BEAM, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_LOW_BEAM, + hmi_apis::Common_LightName::eType::FRONT_LEFT_PARKING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_PARKING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_DAYTIME_RUNNING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_DAYTIME_RUNNING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_TAIL_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_TAIL_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_BRAKE_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_BRAKE_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_REGISTRATION_PLATE_LIGHT, + hmi_apis::Common_LightName::eType::HIGH_BEAMS, + hmi_apis::Common_LightName::eType::LOW_BEAMS, + hmi_apis::Common_LightName::eType::FOG_LIGHTS, + hmi_apis::Common_LightName::eType::RUNNING_LIGHTS, + hmi_apis::Common_LightName::eType::PARKING_LIGHTS, + hmi_apis::Common_LightName::eType::BRAKE_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_REVERSING_LIGHTS, + hmi_apis::Common_LightName::eType::SIDE_MARKER_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_TURN_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_TURN_LIGHTS, + hmi_apis::Common_LightName::eType::HAZARD_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_CARGO_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_TRUCK_BED_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_TRAILER_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_SPOT_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_SPOT_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_PUDDLE_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_PUDDLE_LIGHTS, + hmi_apis::Common_LightName::eType::AMBIENT_LIGHTS, + hmi_apis::Common_LightName::eType::OVERHEAD_LIGHTS, + hmi_apis::Common_LightName::eType::READING_LIGHTS, + hmi_apis::Common_LightName::eType::TRUNK_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_FRONT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_REAR_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_LEFT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_RIGHT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_ALL_LIGHTS}; + +const std::vector light_name_string_values{ + {"FRONT_LEFT_HIGH_BEAM"}, + {"FRONT_RIGHT_HIGH_BEAM"}, + {"FRONT_LEFT_LOW_BEAM"}, + {"FRONT_RIGHT_LOW_BEAM"}, + {"FRONT_LEFT_PARKING_LIGHT"}, + {"FRONT_RIGHT_PARKING_LIGHT"}, + {"FRONT_LEFT_FOG_LIGHT"}, + {"FRONT_RIGHT_FOG_LIGHT"}, + {"FRONT_LEFT_DAYTIME_RUNNING_LIGHT"}, + {"FRONT_RIGHT_DAYTIME_RUNNING_LIGHT"}, + {"FRONT_LEFT_TURN_LIGHT"}, + {"FRONT_RIGHT_TURN_LIGHT"}, + {"REAR_LEFT_FOG_LIGHT"}, + {"REAR_RIGHT_FOG_LIGHT"}, + {"REAR_LEFT_TAIL_LIGHT"}, + {"REAR_RIGHT_TAIL_LIGHT"}, + {"REAR_LEFT_BRAKE_LIGHT"}, + {"REAR_RIGHT_BRAKE_LIGHT"}, + {"REAR_LEFT_TURN_LIGHT"}, + {"REAR_RIGHT_TURN_LIGHT"}, + {"REAR_REGISTRATION_PLATE_LIGHT"}, + {"HIGH_BEAMS"}, + {"LOW_BEAMS"}, + {"FOG_LIGHTS"}, + {"RUNNING_LIGHTS"}, + {"PARKING_LIGHTS"}, + {"BRAKE_LIGHTS"}, + {"REAR_REVERSING_LIGHTS"}, + {"SIDE_MARKER_LIGHTS"}, + {"LEFT_TURN_LIGHTS"}, + {"RIGHT_TURN_LIGHTS"}, + {"HAZARD_LIGHTS"}, + {"REAR_CARGO_LIGHTS"}, + {"REAR_TRUCK_BED_LIGHTS"}, + {"REAR_TRAILER_LIGHTS"}, + {"LEFT_SPOT_LIGHTS"}, + {"RIGHT_SPOT_LIGHTS"}, + {"LEFT_PUDDLE_LIGHTS"}, + {"RIGHT_PUDDLE_LIGHTS"}, + {"AMBIENT_LIGHTS"}, + {"OVERHEAD_LIGHTS"}, + {"READING_LIGHTS"}, + {"TRUNK_LIGHTS"}, + {"EXTERIOR_FRONT_LIGHTS"}, + {"EXTERIOR_REAR_LIGHTS"}, + {"EXTERIOR_LEFT_LIGHTS"}, + {"EXTERIOR_RIGHT_LIGHTS"}, + {"EXTERIOR_ALL_LIGHTS"}}; + +void InitLightNameStringToEnumMap( + LightNameCStringToEnumMap& out_light_names_map) { + for (size_t i = 0; i < light_name_string_values.size(); ++i) { + out_light_names_map[light_name_string_values[i]] = + light_name_enum_values[i]; } -}; - -typedef std:: - map - CStringToEnumMap; +} -CStringToEnumMap InitCStringToEnumMap() { - size_t value = sizeof(cstring_values_) / sizeof(cstring_values_[0]); - CStringToEnumMap result; - for (size_t i = 0; i < value; ++i) { - result[cstring_values_[i]] = enum_values_[i]; +bool LightNameStringToEnum(const std::string& light_name_str, + hmi_apis::Common_LightName::eType& out_value) { + auto it = light_names_map.find(light_name_str); + if (it == light_names_map.end()) { + return false; } - return result; + out_value = it->second; + return true; } -bool StringToEnum(const char* str, hmi_apis::Common_Language::eType& value) { - size_t count_value = sizeof(cstring_values_) / sizeof(cstring_values_[0]); - CStringToEnumMap result; - for (size_t i = 0; i < count_value; ++i) { - result[cstring_values_[i]] = enum_values_[i]; +void InitLanguageStringToEnumMap(LanguageCStringToEnumMap& out_languages_map) { + for (size_t i = 0; i < language_string_values.size(); ++i) { + out_languages_map[language_string_values[i]] = language_enum_values[i]; } +} - CStringToEnumMap::const_iterator it = result.find(str); - if (it == result.end()) { +bool LanguageStringToEnum(const std::string& language_str, + hmi_apis::Common_Language::eType& out_value) { + LanguageCStringToEnumMap::const_iterator it = + languages_map.find(language_str); + if (it == languages_map.end()) { return false; } - value = it->second; + out_value = it->second; return true; } hmi_apis::Common_Language::eType TestCommonLanguageFromString( const std::string& language) { hmi_apis::Common_Language::eType value; - if (StringToEnum(language.c_str(), value)) { + if (LanguageStringToEnum(language, value)) { return value; } return hmi_apis::Common_Language::INVALID_ENUM; } -TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { - const std::string hmi_capabilities_file = "hmi_capabilities.json"; - EXPECT_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CommonLanguageFromString(_)) - .WillRepeatedly(Invoke(TestCommonLanguageFromString)); +hmi_apis::Common_LightName::eType TestCommonLightNameFromString( + const std::string& light_name_str) { + hmi_apis::Common_LightName::eType value; + if (LightNameStringToEnum(light_name_str, value)) { + return value; + } + return hmi_apis::Common_LightName::INVALID_ENUM; +} + +bool IsLightNameExists(const hmi_apis::Common_LightName::eType& light_name) { + auto it = std::find( + light_name_enum_values.begin(), light_name_enum_values.end(), light_name); + return !(it == light_name_enum_values.end()); +} + +class HMICapabilitiesTest : public ::testing::Test { + protected: + HMICapabilitiesTest() + : last_state_wrapper_(std::make_shared( + std::make_shared(kAppStorageFolder, + kAppInfoStorage))) { + if (languages_map.empty()) { + InitLanguageStringToEnumMap(languages_map); + } + if (light_names_map.empty()) { + InitLightNameStringToEnumMap(light_names_map); + } + } + + void SetUp() OVERRIDE { + ON_CALL(mock_app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(mock_app_mngr_, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings_)); + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(kHmiCapabilitiesDefaultFile)); + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(kHmiCapabilitiesCacheFile)); + + hmi_capabilities_ = std::make_shared(mock_app_mngr_); + } - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); + void TearDown() OVERRIDE { + DeleteFileIfExists(kHmiCapabilitiesCacheFile); + DeleteFileIfExists(kAppInfoDataFile); + hmi_capabilities_.reset(); + } + + void CreateFile(const std::string& file_name) { + file_system::CreateFile(file_name); + ASSERT_TRUE(file_system::FileExists(file_name)); + } + + void DeleteFileIfExists(const std::string& file_path) { + if (file_system::FileExists(file_path)) { + EXPECT_TRUE(::file_system::DeleteFile(file_path)); + } } - EXPECT_CALL(app_mngr_, IsSOStructValid(_, _)).WillOnce(Return(true)); - EXPECT_TRUE(hmi_capabilities_test->LoadCapabilitiesFromFile()); + void SetUpLanguageAndLightCapabilitiesExpectation() { + ON_CALL(mock_app_mngr_, IsSOStructValid(_, _)).WillByDefault(Return(true)); + + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLanguageFromString(_)) + .WillRepeatedly(Invoke(TestCommonLanguageFromString)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLightNameFromString(_)) + .WillRepeatedly(Invoke(TestCommonLightNameFromString)); + } + + std::shared_ptr hmi_capabilities_; + NiceMock mock_app_mngr_; + NiceMock mock_event_dispatcher_; + NiceMock mock_application_manager_settings_; + resumption::LastStateWrapperPtr last_state_wrapper_; + smart_objects::CSmartSchema schema_; +}; + +TEST_F(HMICapabilitiesTest, + Init_CheckActiveLanguages_SuccesSetupDefaultLanguages) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); - // Check active languages EXPECT_EQ(hmi_apis::Common_Language::EN_US, - hmi_capabilities_test->active_ui_language()); - EXPECT_EQ(hmi_apis::Common_Language::ES_MX, - hmi_capabilities_test->active_vr_language()); - EXPECT_EQ(hmi_apis::Common_Language::DE_DE, - hmi_capabilities_test->active_tts_language()); + hmi_capabilities_->active_ui_language()); + EXPECT_EQ(hmi_apis::Common_Language::EN_US, + hmi_capabilities_->active_vr_language()); + EXPECT_EQ(hmi_apis::Common_Language::EN_US, + hmi_capabilities_->active_tts_language()); +} - // Check UI languages - const smart_objects::SmartObject ui_supported_languages = - *(hmi_capabilities_test->ui_supported_languages()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckUILanguages_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto ui_supported_languages_so = + *(hmi_capabilities_->ui_supported_languages()); EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast( - ui_supported_languages[0].asInt())); + ui_supported_languages_so[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast( - ui_supported_languages[1].asInt())); + ui_supported_languages_so[1].asInt())); EXPECT_EQ(hmi_apis::Common_Language::FR_CA, static_cast( - ui_supported_languages[2].asInt())); + ui_supported_languages_so[2].asInt())); +} - // Check VR languages - const smart_objects::SmartObject vr_supported_languages = - *(hmi_capabilities_test->vr_supported_languages()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVRLanguages_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vr_supported_languages_so = + *(hmi_capabilities_->vr_supported_languages()); - EXPECT_EQ(hmi_apis::Common_Language::AR_SA, - static_cast( - vr_supported_languages[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast( - vr_supported_languages[1].asInt())); + vr_supported_languages_so[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast( - vr_supported_languages[2].asInt())); + vr_supported_languages_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::FR_CA, + static_cast( + vr_supported_languages_so[2].asInt())); +} - // Check TTS languages - const smart_objects::SmartObject tts_supported_languages = - *(hmi_capabilities_test->tts_supported_languages()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckTTSSupportedLanguages_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto tts_supported_languages_so = + *(hmi_capabilities_->tts_supported_languages()); - EXPECT_EQ(hmi_apis::Common_Language::DA_DK, + EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast( - tts_supported_languages[0].asInt())); - EXPECT_EQ(hmi_apis::Common_Language::CS_CZ, + tts_supported_languages_so[0].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast( - tts_supported_languages[1].asInt())); - EXPECT_EQ(hmi_apis::Common_Language::KO_KR, + tts_supported_languages_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::FR_CA, static_cast( - tts_supported_languages[2].asInt())); + tts_supported_languages_so[2].asInt())); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSpeechCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto tts_capabilities_so = *(hmi_capabilities_->speech_capabilities()); - // Check TTS capabilities - const smart_objects::SmartObject tts_capabilities = - *(hmi_capabilities_test->speech_capabilities()); EXPECT_EQ(hmi_apis::Common_SpeechCapabilities::SC_TEXT, static_cast( - tts_capabilities[0].asInt())); + tts_capabilities_so[0].asInt())); +} - // Check button capabilities - const smart_objects::SmartObject buttons_capabilities_so = - *(hmi_capabilities_test->button_capabilities()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckUIButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto buttons_capabilities_so = + *(hmi_capabilities_->button_capabilities()); // Count of buttons in json file - const uint32_t btn_length = buttons_capabilities_so.length(); - EXPECT_EQ(16u, btn_length); - for (uint32_t i = 0; i < btn_length; ++i) { - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists(strings::name)); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("shortPressAvailable")); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("longPressAvailable")); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("upDownAvailable")); - EXPECT_TRUE(buttons_capabilities_so[i]["shortPressAvailable"].asBool()); - EXPECT_TRUE(buttons_capabilities_so[i]["longPressAvailable"].asBool()); - EXPECT_TRUE(buttons_capabilities_so[i]["upDownAvailable"].asBool()); + const size_t btn_length = buttons_capabilities_so.length(); + EXPECT_EQ(16ull, btn_length); + for (size_t index = 0; index < btn_length; ++index) { + EXPECT_TRUE(buttons_capabilities_so + [index][rc_rpc_plugin::enums_value::kShortPressAvailable] + .asBool()); + EXPECT_TRUE( + buttons_capabilities_so[index] + [rc_rpc_plugin::enums_value::kLongPressAvailable] + .asBool()); + EXPECT_TRUE( + buttons_capabilities_so[index] + [rc_rpc_plugin::enums_value::kUpDownAvailable] + .asBool()); } - const smart_objects::SmartObject display_capabilities_so = - *(hmi_capabilities_test->display_capabilities()); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckDisplayType_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); - // Check display type - EXPECT_EQ(hmi_apis::Common_DisplayType::GEN2_8_DMA, + EXPECT_EQ(hmi_apis::Common_DisplayType::SDL_GENERIC, static_cast( display_capabilities_so[hmi_response::display_type].asInt())); @@ -281,51 +458,79 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { display_capabilities_so[hmi_response::display_name].asString()); EXPECT_TRUE(display_capabilities_so["graphicSupported"].asBool()); +} - // Check text fields - const uint32_t text_len = - display_capabilities_so[hmi_response::text_fields].length(); - EXPECT_NE(0u, text_len); - for (uint32_t i = 0; i < text_len; ++i) { - EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][i]) - .keyExists(strings::name)); - EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][i]) - .keyExists(strings::character_set)); - } - - // Check image fields - EXPECT_TRUE((display_capabilities_so).keyExists(hmi_response::image_fields)); - const uint32_t img_len = +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckImageFields_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); + + ASSERT_TRUE((display_capabilities_so).keyExists(hmi_response::image_fields)); + const size_t img_len = display_capabilities_so[hmi_response::image_fields].length(); - EXPECT_NE(0u, img_len); - for (uint32_t i = 0; i < img_len; ++i) { - EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][i]) + EXPECT_NE(0ull, img_len); + for (size_t index = 0; index < img_len; ++index) { + EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][index]) .keyExists(strings::name)); - EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][i]) - .keyExists(strings::image_type_supported)); - if (display_capabilities_so[hmi_response::image_fields][i][strings::name] == - hmi_apis::Common_ImageFieldName::locationImage) { + + const hmi_apis::Common_ImageFieldName::eType field_name = + static_cast( + display_capabilities_so[hmi_response::image_fields][index] + [strings::name] + .asInt()); + + if ((field_name == hmi_apis::Common_ImageFieldName::locationImage) || + (field_name == hmi_apis::Common_ImageFieldName::alertIcon)) { + EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][index]) + .keyExists(strings::image_type_supported)); EXPECT_EQ(hmi_apis::Common_FileType::GRAPHIC_PNG, static_cast( - display_capabilities_so[hmi_response::image_fields][i] + display_capabilities_so[hmi_response::image_fields][index] [strings::image_type_supported][0] .asInt())); } } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckTextFields_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); + + const size_t text_len = + display_capabilities_so[hmi_response::text_fields].length(); + EXPECT_NE(0ull, text_len); + for (size_t index = 0; index < text_len; ++index) { + EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][index]) + .keyExists(strings::name)); + EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][index]) + .keyExists(strings::character_set)); + } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckMediaClockFormats_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); - // Check media clock formats EXPECT_TRUE( (display_capabilities_so).keyExists(hmi_response::media_clock_formats)); - const uint32_t media_length = + const size_t media_length = display_capabilities_so[hmi_response::media_clock_formats].length(); - EXPECT_NE(0u, media_length); - for (uint32_t i = 0; i < media_length; ++i) { + EXPECT_NE(0ull, media_length); + for (size_t i = 0; i < media_length; ++i) { EXPECT_EQ( i, display_capabilities_so[hmi_response::media_clock_formats][i].asUInt()); } - EXPECT_TRUE( + ASSERT_TRUE( (display_capabilities_so).keyExists(hmi_response::image_capabilities)); EXPECT_EQ(hmi_apis::Common_ImageType::DYNAMIC, static_cast( @@ -336,9 +541,17 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { display_capabilities_so[hmi_response::image_capabilities][1] .asInt())); - // Check audio pass thru - const smart_objects::SmartObject audio_pass_thru_capabilities_so = - *(hmi_capabilities_test->audio_pass_thru_capabilities()); + // TemplatesAvailable parameter could be as empty array + ASSERT_TRUE( + display_capabilities_so.keyExists(hmi_response::templates_available)); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckAudioPassThru_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto audio_pass_thru_capabilities_so = + *(hmi_capabilities_->audio_pass_thru_capabilities()); + EXPECT_EQ(smart_objects::SmartType_Array, audio_pass_thru_capabilities_so.getType()); EXPECT_EQ(1u, audio_pass_thru_capabilities_so.length()); @@ -351,57 +564,118 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { EXPECT_EQ(hmi_apis::Common_AudioType::PCM, static_cast( audio_pass_thru_capabilities_so[0]["audioType"].asInt())); +} + +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckHmiZoneCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto hmi_zone_capabilities_so = + *(hmi_capabilities_->hmi_zone_capabilities()); - // Check hmi zone capabilities - const smart_objects::SmartObject hmi_zone_capabilities_so = - *(hmi_capabilities_test->hmi_zone_capabilities()); EXPECT_EQ(hmi_apis::Common_HmiZoneCapabilities::FRONT, static_cast( hmi_zone_capabilities_so.asInt())); +} - const smart_objects::SmartObject soft_button_capabilities_so = - *(hmi_capabilities_test->soft_button_capabilities()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSoftButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto& soft_button_capabilities_so = + *(hmi_capabilities_->soft_button_capabilities()); + + const size_t soft_butons_length = soft_button_capabilities_so.length(); + + ASSERT_TRUE(soft_butons_length > 0); + + for (size_t index = 0; index < soft_butons_length; ++index) { + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kShortPressAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kShortPressAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kLongPressAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kLongPressAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kUpDownAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kUpDownAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + hmi_response::image_supported)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so[index][hmi_response::image_supported] + .getType()); + } +} - EXPECT_TRUE(soft_button_capabilities_so[0]["shortPressAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["longPressAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["upDownAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["imageSupported"].asBool()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckPresetBankCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto preset_bank_so = *(hmi_capabilities_->preset_bank_capabilities()); - const smart_objects::SmartObject preset_bank_so = - *(hmi_capabilities_test->preset_bank_capabilities()); - EXPECT_TRUE(preset_bank_so["onScreenPresetsAvailable"].asBool()); + EXPECT_TRUE( + preset_bank_so.keyExists(hmi_response::on_screen_presets_available)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + preset_bank_so[hmi_response::on_screen_presets_available].getType()); +} - // Check vehicle type - const smart_objects::SmartObject vehicle_type_so = - *(hmi_capabilities_test->vehicle_type()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVehicleType_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vehicle_type_so = *(hmi_capabilities_->vehicle_type()); - EXPECT_EQ("Ford", vehicle_type_so["make"].asString()); - EXPECT_EQ("Fiesta", vehicle_type_so["model"].asString()); - EXPECT_EQ("2013", vehicle_type_so["modelYear"].asString()); + EXPECT_EQ("SDL", vehicle_type_so["make"].asString()); + EXPECT_EQ("Generic", vehicle_type_so["model"].asString()); + EXPECT_EQ("2019", vehicle_type_so["modelYear"].asString()); EXPECT_EQ("SE", vehicle_type_so["trim"].asString()); +} - // Check system capabilities - smart_objects::SmartObject navigation_capability_so = - *(hmi_capabilities_test->navigation_capability()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckNavigationCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto navigation_capability_so = + *(hmi_capabilities_->navigation_capability()); EXPECT_TRUE(navigation_capability_so.keyExists("sendLocationEnabled")); EXPECT_TRUE(navigation_capability_so.keyExists("getWayPointsEnabled")); EXPECT_TRUE(navigation_capability_so["sendLocationEnabled"].asBool()); EXPECT_TRUE(navigation_capability_so["getWayPointsEnabled"].asBool()); - // since we have navigation capabilities, the feature should be supported - EXPECT_TRUE(hmi_capabilities_test->navigation_supported()); + // Since we have navigation capabilities, the feature should be supported + EXPECT_TRUE(hmi_capabilities_->navigation_supported()); +} - const smart_objects::SmartObject phone_capability_so = - *(hmi_capabilities_test->phone_capability()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckPhoneCapability_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto phone_capability_so = *(hmi_capabilities_->phone_capability()); EXPECT_TRUE(phone_capability_so.keyExists("dialNumberEnabled")); EXPECT_TRUE(phone_capability_so["dialNumberEnabled"].asBool()); - EXPECT_TRUE(hmi_capabilities_test->phone_call_supported()); + EXPECT_TRUE(hmi_capabilities_->phone_call_supported()); +} - const smart_objects::SmartObject vs_capability_so = - *(hmi_capabilities_test->video_streaming_capability()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVideoStreamingCapability_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vs_capability_so = + *(hmi_capabilities_->video_streaming_capability()); EXPECT_TRUE(vs_capability_so.keyExists(strings::preferred_resolution)); EXPECT_TRUE(vs_capability_so[strings::preferred_resolution].keyExists( @@ -419,156 +693,312 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { EXPECT_TRUE(vs_capability_so.keyExists(strings::max_bitrate)); EXPECT_EQ(10000, vs_capability_so[strings::max_bitrate].asInt()); EXPECT_TRUE(vs_capability_so.keyExists(strings::supported_formats)); - const uint32_t supported_formats_len = + const size_t supported_formats_len = vs_capability_so[strings::supported_formats].length(); - EXPECT_EQ(2u, supported_formats_len); + EXPECT_EQ(1ull, supported_formats_len); + EXPECT_TRUE(vs_capability_so[strings::supported_formats][0].keyExists( strings::protocol)); EXPECT_TRUE(vs_capability_so[strings::supported_formats][0].keyExists( strings::codec)); - EXPECT_EQ(0, + EXPECT_EQ(hmi_apis::Common_VideoStreamingProtocol::RAW, vs_capability_so[strings::supported_formats][0][strings::protocol] .asInt()); EXPECT_EQ( - 0, + hmi_apis::Common_VideoStreamingCodec::H264, vs_capability_so[strings::supported_formats][0][strings::codec].asInt()); - EXPECT_TRUE(vs_capability_so[strings::supported_formats][1].keyExists( - strings::protocol)); - EXPECT_TRUE(vs_capability_so[strings::supported_formats][1].keyExists( - strings::codec)); - EXPECT_EQ(1, - vs_capability_so[strings::supported_formats][1][strings::protocol] - .asInt()); - EXPECT_EQ( - 2, - vs_capability_so[strings::supported_formats][1][strings::codec].asInt()); EXPECT_TRUE( vs_capability_so.keyExists(strings::haptic_spatial_data_supported)); - EXPECT_TRUE( + EXPECT_FALSE( vs_capability_so[strings::haptic_spatial_data_supported].asBool()); - EXPECT_TRUE(hmi_capabilities_test->video_streaming_supported()); - - // Check remote control capabilites - const smart_objects::SmartObject rc_capability_so = - *(hmi_capabilities_test->rc_capability()); + EXPECT_TRUE(hmi_capabilities_->video_streaming_supported()); +} - EXPECT_TRUE(rc_capability_so.keyExists("climateControlCapabilities")); - EXPECT_TRUE(rc_capability_so.keyExists("radioControlCapabilities")); - EXPECT_TRUE(rc_capability_so.keyExists("buttonCapabilities")); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRemoteControlCapabilites_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kclimateControlCapabilities)); + const auto& climate_control_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kclimateControlCapabilities][0]; + + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kFanSpeedAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kDesiredTemperatureAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kAcEnableAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kAcMaxEnableAvailable] + .asBool()); +} +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRadioControlCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kradioControlCapabilities)); + const auto& radio_control_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kradioControlCapabilities][0]; + + EXPECT_EQ("radio", radio_control_capabilities_so["moduleName"].asString()); + + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::message_params::kAvailableHdChannelsAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSignalChangeThresholdAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSignalStrengthAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kHdRadioEnableAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSiriusxmRadioAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["fanSpeedAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kSisDataAvailable] .asBool()); - EXPECT_TRUE(rc_capability_so["climateControlCapabilities"][0] - ["desiredTemperatureAvailable"] - .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["acEnableAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kStateAvailable] .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["acMaxEnableAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kRadioBandAvailable] .asBool()); - + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kRadioFrequencyAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["radioBandAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kHdChannelAvailable] .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["radioFrequencyAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kRdsDataAvailable] .asBool()); + + ASSERT_TRUE(radio_control_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + ASSERT_TRUE( + radio_control_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo] + .keyExists(rc_rpc_plugin::message_params::kModuleId)); +} + +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRCButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE( + rc_capability_so.keyExists(rc_rpc_plugin::strings::kbuttonCapabilities)); + const auto& button_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kbuttonCapabilities]; + + const size_t button_capabilities_length = button_capabilities_so.length(); + + for (size_t index = 0; index < button_capabilities_length; ++index) { + ASSERT_TRUE(button_capabilities_so[index].keyExists("name")); + + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kLongPressAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kLongPressAvailable] + .getType()); + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kShortPressAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kShortPressAvailable] + .getType()); + + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kUpDownAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kUpDownAvailable] + .getType()); + } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckAudioCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kaudioControlCapabilities)); + + const auto& audio_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kaudioControlCapabilities][0]; + + EXPECT_TRUE(audio_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + + const auto& audio_cap_module_info = + audio_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; + EXPECT_TRUE(audio_cap_module_info.keyExists( + rc_rpc_plugin::message_params::kModuleId)); + EXPECT_TRUE(audio_cap_module_info.keyExists( + rc_rpc_plugin::strings::kAllowMultipleAccess)); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["hdChannelAvailable"] + audio_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] .asBool()); + + EXPECT_TRUE( + audio_capabilities_so[rc_rpc_plugin::strings::kSourceAvailable].asBool()); + EXPECT_TRUE( + audio_capabilities_so[rc_rpc_plugin::strings::kVolumeAvailable].asBool()); + EXPECT_TRUE(audio_capabilities_so[rc_rpc_plugin::strings::kEqualizerAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["rdsDataAvailable"] + audio_capabilities_so[rc_rpc_plugin::strings::kKeepContextAvailable] .asBool()); + EXPECT_EQ( + kEqualizerMaxChanelId, + audio_capabilities_so[rc_rpc_plugin::strings::kEqualizerMaxChannelId] + .asInt()); +} - EXPECT_TRUE(rc_capability_so["buttonCapabilities"][0]["shortPressAvailable"] - .asBool()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSeatCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kseatControlCapabilities)); + const auto& seat_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kseatControlCapabilities][0]; + + EXPECT_TRUE(seat_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + const auto& seat_cap_module_info = + seat_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; EXPECT_TRUE( - rc_capability_so["buttonCapabilities"][0]["longPressAvailable"].asBool()); + seat_cap_module_info.keyExists(rc_rpc_plugin::message_params::kModuleId)); + EXPECT_TRUE(seat_cap_module_info.keyExists( + rc_rpc_plugin::strings::kAllowMultipleAccess)); EXPECT_FALSE( - rc_capability_so["buttonCapabilities"][0]["upDownAvailable"].asBool()); + seat_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] + .asBool()); } TEST_F(HMICapabilitiesTest, - LoadCapabilitiesFromFileAndVerifyUnsupportedSystemCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; + LoadCapabilitiesFromFile_CheckLightCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)); + const auto& light_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::klightControlCapabilities]; + + EXPECT_TRUE(light_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + const auto& light_cap_module_info = + light_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; + EXPECT_TRUE(light_cap_module_info.keyExists( + rc_rpc_plugin::message_params::kModuleId)); + EXPECT_FALSE( + light_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] + .asBool()); - const std::string hmi_capabilities_file = "hmi_capabilities_sc1.json"; + EXPECT_TRUE(light_capabilities_so.keyExists( + rc_rpc_plugin::strings::kSupportedLights)); + + const auto& supported_lights = + light_capabilities_so[rc_rpc_plugin::strings::kSupportedLights]; + + const size_t supported_lights_length = supported_lights.length(); + for (size_t index = 0; index < supported_lights_length; ++index) { + EXPECT_TRUE( + IsLightNameExists(static_cast( + supported_lights[index]["name"].asInt()))); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kStatusAvailable)); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kDensityAvailable)); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kRGBColorSpaceAvailable)); + } + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)); + const auto& light_ctrl_cap_so = + rc_capability_so[rc_rpc_plugin::strings::klightControlCapabilities]; + + EXPECT_TRUE(light_ctrl_cap_so.keyExists("moduleName")); + EXPECT_TRUE( + light_ctrl_cap_so.keyExists(rc_rpc_plugin::strings::kSupportedLights)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Array, + light_ctrl_cap_so[rc_rpc_plugin::strings::kSupportedLights].getType()); + + const auto& supported_light_so = + light_ctrl_cap_so[rc_rpc_plugin::strings::kSupportedLights]; - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); - - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); + const size_t sup_lights_length = supported_light_so.length(); + + for (size_t index = 0; index < sup_lights_length; ++index) { + EXPECT_TRUE( + supported_light_so[index].keyExists(rc_rpc_plugin::strings::kName)); } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFileAndVerifyUnsupportedSystemCapabilities) { + const std::string hmi_capabilities_file = "hmi_capabilities_sc1.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - std::shared_ptr hmi_capabilities = - std::make_shared(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // Check system capabilities; only phone capability is available - EXPECT_FALSE(hmi_capabilities->navigation_supported()); - EXPECT_TRUE(hmi_capabilities->phone_call_supported()); - EXPECT_FALSE(hmi_capabilities->video_streaming_supported()); - EXPECT_FALSE(hmi_capabilities->rc_supported()); + EXPECT_FALSE(hmi_capabilities_->navigation_supported()); + EXPECT_TRUE(hmi_capabilities_->phone_call_supported()); + EXPECT_FALSE(hmi_capabilities_->video_streaming_supported()); + EXPECT_FALSE(hmi_capabilities_->rc_supported()); // verify phone capability const smart_objects::SmartObject phone_capability_so = - *(hmi_capabilities->phone_capability()); + *(hmi_capabilities_->phone_capability()); EXPECT_TRUE(phone_capability_so.keyExists("dialNumberEnabled")); EXPECT_TRUE(phone_capability_so["dialNumberEnabled"].asBool()); } TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFileAndVerifyEmptySystemCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; - const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); - - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - - std::shared_ptr hmi_capabilities = - std::make_shared(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // Check system capabilities; only navigation capability is valid, the other // two are empty - EXPECT_TRUE(hmi_capabilities->navigation_supported()); - EXPECT_FALSE(hmi_capabilities->phone_call_supported()); - EXPECT_FALSE(hmi_capabilities->video_streaming_supported()); - EXPECT_FALSE(hmi_capabilities->rc_supported()); + EXPECT_TRUE(hmi_capabilities_->navigation_supported()); + EXPECT_FALSE(hmi_capabilities_->phone_call_supported()); + EXPECT_FALSE(hmi_capabilities_->video_streaming_supported()); + EXPECT_FALSE(hmi_capabilities_->rc_supported()); // verify navigation capabilities smart_objects::SmartObject navigation_capability_so = - *(hmi_capabilities->navigation_capability()); + *(hmi_capabilities_->navigation_capability()); EXPECT_TRUE(navigation_capability_so.keyExists("sendLocationEnabled")); EXPECT_TRUE(navigation_capability_so.keyExists("getWayPointsEnabled")); EXPECT_TRUE(navigation_capability_so["sendLocationEnabled"].asBool()); @@ -577,41 +1007,23 @@ TEST_F(HMICapabilitiesTest, TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFileAndVerifyOldAudioPassThruCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; - const std::string hmi_capabilities_file = "hmi_capabilities_old_apt.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), CommonLanguageFromString(_)) .WillRepeatedly(Invoke(TestCommonLanguageFromString)); - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - - std::shared_ptr hmi_capabilities = - std::make_shared(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // with old audio pass thru format, the object is an array containing a single // object smart_objects::SmartObjectSPtr audio_pass_thru_capabilities_so = - hmi_capabilities->audio_pass_thru_capabilities(); + hmi_capabilities_->audio_pass_thru_capabilities(); EXPECT_EQ(smart_objects::SmartType_Array, audio_pass_thru_capabilities_so->getType()); - EXPECT_EQ(1u, audio_pass_thru_capabilities_so->length()); + EXPECT_EQ(1ull, audio_pass_thru_capabilities_so->length()); smart_objects::SmartObject& first_element = (*audio_pass_thru_capabilities_so)[0]; EXPECT_TRUE(first_element.keyExists("samplingRate")); @@ -629,45 +1041,608 @@ TEST_F(HMICapabilitiesTest, } TEST_F(HMICapabilitiesTest, VerifyImageType) { + ON_CALL(mock_app_mngr_, IsSOStructValid(_, _)).WillByDefault(Return(true)); + const int32_t image_type = 1; smart_objects::SmartObject sm_obj; - EXPECT_CALL(app_mngr_, IsSOStructValid(_, _)).WillOnce(Return(true)); sm_obj[hmi_response::image_capabilities][0] = image_type; - hmi_capabilities_test->set_display_capabilities(sm_obj); + hmi_capabilities_->set_display_capabilities(sm_obj); - EXPECT_TRUE(hmi_capabilities_test->VerifyImageType(image_type)); + EXPECT_TRUE(hmi_capabilities_->VerifyImageType(image_type)); const int32_t new_image_type = 2; - EXPECT_FALSE(hmi_capabilities_test->VerifyImageType(new_image_type)); -} - -void HMICapabilitiesTest::SetCooperating() { - smart_objects::SmartObjectSPtr test_so; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(_, _)) - .WillRepeatedly(Return(test_so)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) - .WillRepeatedly(Return(true)); + EXPECT_FALSE(hmi_capabilities_->VerifyImageType(new_image_type)); } TEST_F(HMICapabilitiesTest, SetVRCooperating) { - hmi_capabilities_test->set_is_vr_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_vr_cooperating()); + hmi_capabilities_->set_is_vr_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_vr_cooperating()); } TEST_F(HMICapabilitiesTest, SetTTSCooperating) { - hmi_capabilities_test->set_is_tts_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_tts_cooperating()); + hmi_capabilities_->set_is_tts_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_tts_cooperating()); } TEST_F(HMICapabilitiesTest, SetUICooperating) { - hmi_capabilities_test->set_is_ui_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_ui_cooperating()); + hmi_capabilities_->set_is_ui_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_ui_cooperating()); } TEST_F(HMICapabilitiesTest, SetIviCooperating) { - hmi_capabilities_test->set_is_ivi_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_ivi_cooperating()); + hmi_capabilities_->set_is_ivi_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_ivi_cooperating()); +} + +TEST_F( + HMICapabilitiesTest, + UpdateCapabilitiesDependingOn_ccpuVersion_FromCacheForOld_RequestForNew) { + const std::string ccpu_version = "4.1.3.B_EB355B"; + const std::string ccpu_version_new = "5.1.3.B_EB355B"; + const std::string hmi_capabilities_invalid_file = + "hmi_capabilities_invalid_file.json"; + + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + EXPECT_CALL(mock_app_mngr_, RequestForInterfacesAvailability()).Times(2); + + hmi_capabilities_->set_ccpu_version(ccpu_version); + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); + + EXPECT_EQ(ccpu_version, hmi_capabilities_->ccpu_version()); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version_new); + EXPECT_EQ(ccpu_version_new, hmi_capabilities_->ccpu_version()); +} + +TEST_F(HMICapabilitiesTest, + UpdateCapabilitiesForNew_ccpuVersion_DeleteCacheFile) { + MockApplicationManagerSettings mock_application_manager_settings; + const std::string ccpu_version = "4.1.3.B_EB355B"; + const std::string ccpu_version_new = "5.1.3.B_EB355B"; + const std::string hmi_capabilities_invalid_file = + "hmi_capabilities_invalid_file.json"; + + CreateFile(kHmiCapabilitiesCacheFile); + + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + + hmi_capabilities_->set_ccpu_version(ccpu_version); + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version_new); + EXPECT_EQ(ccpu_version_new, hmi_capabilities_->ccpu_version()); + + EXPECT_FALSE(file_system::FileExists(kHmiCapabilitiesCacheFile)); +} + +TEST_F( + HMICapabilitiesTest, + OnSoftwareVersionReceived_CcpuMatchNoPendingRequestsForCapability_SetHMICooperatingToTrue) { + // If local ccpu_version matches with the received ccpu_version from the HMI, + // and cache exists, SDL Core should check if hmi_cooperating is set to true + // if yes - SDL should respond to all pending RAI requests, if they exist. + // hmi_cooperting is set to true when no pending capability requests exist + const std::string ccpu_version = "4.1.3.B_EB355B"; + + hmi_capabilities_->set_ccpu_version(ccpu_version); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); +} + +TEST_F( + HMICapabilitiesTest, + OnSoftwareVersionReceived_CcpuMatchHavePendingRequestsForCapability_NoSetHMICooperatingToTrue) { + // If local ccpu_version matches with the received ccpu_version from the HMI, + // and there is no cache, SDL Core should check if hmi_cooperating is set to + // true if no - SDL should suspend all RAI responses (if any) and wait for HMI + // responses with all required capabilities. The RAI responses (if any) could + // be handled only after hmi_cooperating is set to true, it is set when all + // capabilities responses are received from the HMI + const std::string ccpu_version = "4.1.3.B_EB355B"; + + // Init() is required to set pending capabilities requests to the HMI + hmi_capabilities_->Init(last_state_wrapper_); + hmi_capabilities_->set_ccpu_version(ccpu_version); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)).Times(0); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); +} + +TEST_F(HMICapabilitiesTest, + CacheFileNameNotSpecified_NoNeedToSave_ReturnSuccess) { + const std::string hmi_capabilities_empty_file_name = ""; + const std::vector sections_to_update{hmi_response::language}; + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_empty_file_name)); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, SaveCachedCapabilitiesToFile_ParseFile_Failed) { + const std::vector sections_to_update{hmi_response::language}; + + file_system::CreateFile(kHmiCapabilitiesCacheFile); + EXPECT_TRUE(file_system::FileExists(kHmiCapabilitiesCacheFile)); + + EXPECT_FALSE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_ParsedFieldsSave_Success) { + const std::vector sections_to_update{ + hmi_response::display_capabilities}; + const std::string content_to_save = "{\"field\" : \"value\" }"; + + CreateFile(kHmiCapabilitiesCacheFile); + + const std::vector binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); + + std::string content_after_update; + EXPECT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + EXPECT_NE(content_to_save, content_after_update); +} + +TEST_F( + HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_LanguageIsNotTheSameAsPersisted_SaveNewLanguageToCache) { + SetUpLanguageAndLightCapabilitiesExpectation(); + const std::string new_language = "RU_RU"; + ON_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLanguageToString(_)) + .WillByDefault(Return(new_language)); + + hmi_capabilities_->Init(last_state_wrapper_); + hmi_capabilities_->set_active_tts_language(hmi_apis::Common_Language::RU_RU); + const std::vector sections_to_update{hmi_response::language}; + const std::string content_to_save = "{\"TTS\": {\"language\":\"EN_US\"}}"; + + CreateFile(kHmiCapabilitiesCacheFile); + const std::vector binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); + + std::string content_after_update; + ASSERT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + EXPECT_TRUE(content_after_update.find(new_language) != std::string::npos); +} + +TEST_F( + HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_SectionToUpdateIsEmpty_SkipSaving_ReturnTrue) { + const std::vector sections_to_update; + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + "", sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, PrepareJsonValueForSaving_Success) { + const std::vector sections_to_update{ + hmi_response::display_capabilities, + hmi_response::hmi_zone_capabilities, + hmi_response::soft_button_capabilities, + strings::audio_pass_thru_capabilities, + strings::hmi_capabilities, + strings::system_capabilities, + hmi_response::languages}; + + const std::vector interfaces_name{ + hmi_interface::tts, + hmi_interface::vr, + hmi_interface::ui, + hmi_interface::buttons, + hmi_interface::vehicle_info, + hmi_interface::rc, + hmi_response::speech_capabilities, + hmi_response::prerecorded_speech_capabilities, + hmi_response::button_capabilities, + hmi_response::preset_bank_capabilities}; + + smart_objects::SmartObject audio_capabilities_so( + smart_objects::SmartType_Array); + audio_capabilities_so[0][strings::sampling_rate] = + hmi_apis::Common_SamplingRate::RATE_44KHZ; + audio_capabilities_so[0][strings::bits_per_sample] = + hmi_apis::Common_BitsPerSample::RATE_8_BIT; + audio_capabilities_so[0][strings::audio_type] = + hmi_apis::Common_AudioType::PCM; + + const std::string content_to_save = "{\"field\" : \"value\" }"; + const std::vector binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + + hmi_capabilities_->set_audio_pass_thru_capabilities(audio_capabilities_so); + + CreateFile(kHmiCapabilitiesCacheFile); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + interfaces_name[i], sections_to_update, schema_)); + } + + std::string content_after_update; + EXPECT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + + Json::Value root_node; + utils::JsonReader reader; + ASSERT_TRUE(reader.parse(content_after_update, &root_node)); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(static_cast(root_node[interfaces_name[i]])); + } + EXPECT_TRUE( + root_node[hmi_interface::ui][strings::audio_pass_thru_capabilities] + .isArray()); +} + +TEST_F(HMICapabilitiesTest, + OnCapabilityInitialized_RespondToAllPendingRAIRequestsIfTheyHold) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages}; + + // Contains only UI capabilities + const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + + // Initializes the UI capabilities with the default values + // Other interfaces are absent and appropriate requests should be sent + hmi_capabilities_->Init(last_state_wrapper_); + + ON_CALL(mock_app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + + // Sets isHMICooperating flag to true after all required capabilities are + // received from HMI + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + + for (const auto& request_id : requests_required) { + hmi_capabilities_->UpdateRequestsRequiredForCapabilities(request_id); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyUICapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_ui_capabilities = + "{\"UI\" : {\"language\" : " + "\"EN-US\",\"languages\":[],\"displayCapabilities\" : " + "{},\"audioPassThruCapabilities\":[],\"pcmStreamCapabilities\" : " + "{},\"hmiZoneCapabilities\": \"\",\"softButtonCapabilities\" : " + "[],\"systemCapabilities\" : {}}}"; + + const std::vector binary_data_to_save( + predefined_ui_capabilities.begin(), predefined_ui_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } + + DeleteFileIfExists(hmi_capabilities_cache_file); +} + +TEST_F(HMICapabilitiesTest, + OnlyRCCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_rc_capabilities = + "{\"RC\" : {\"remoteControlCapability\" : {\"buttonCapabilities\": " + "[],\"climateControlCapabilities\": [],\"radioControlCapabilities\": " + "[],\"audioControlCapabilities\": [],\"seatControlCapabilities\": " + "[],\"lightControlCapabilities\": {},\"hmiSettingsControlCapabilities\": " + "{}},\"seatLocationCapability\": {}}}}"; + + const std::vector binary_data_to_save( + predefined_rc_capabilities.begin(), predefined_rc_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyVRCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_vr_capabilities = + "{\"VR\": {\"vrCapabilities\": [],\"language\": \"\",\"languages\": []}}"; + + const std::vector binary_data_to_save( + predefined_vr_capabilities.begin(), predefined_vr_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyTTSCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_tts_capabilities = + "{\"TTS\": {\"speechCapabilities\": [],\"prerecordedSpeechCapabilities\" " + ": [],\"language\": \"\",\"languages\": " + "[]}}"; + + const std::vector binary_data_to_save( + predefined_tts_capabilities.begin(), predefined_tts_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyButtonsSCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_buttons_capabilities = + "{\"Buttons\": {\"capabilities\": [],\"presetBankCapabilities\": {}}}"; + + const std::vector binary_data_to_save( + predefined_buttons_capabilities.begin(), + predefined_buttons_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyVehicleInfoInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_vi_capabilities = + "{\"VehicleInfo\": { \"vehicleType\" : {} }}"; + + const std::vector binary_data_to_save( + predefined_vi_capabilities.begin(), predefined_vi_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F( + HMICapabilitiesTest, + ConvertJsonArrayToSoArray_ConvertPrerecordedSpeech_SuccessConvertFromStringToEnum) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + CreateFile(kHmiCapabilitiesCacheFile); + const std::string prerecordedSpeechCapabilities = + "{ \"TTS\" :{" + "\"prerecordedSpeechCapabilities\" :[" + "\"HELP_JINGLE\"," + "\"INITIAL_JINGLE\"," + "\"LISTEN_JINGLE\"," + "\"POSITIVE_JINGLE\"," + "\"NEGATIVE_JINGLE\"]}" + "}"; + + const std::vector binary_data_to_save( + prerecordedSpeechCapabilities.begin(), + prerecordedSpeechCapabilities.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + hmi_capabilities_->Init(last_state_wrapper_); + + const auto tts_capabilities_so = *(hmi_capabilities_->prerecorded_speech()); + + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::HELP_JINGLE, + static_cast( + tts_capabilities_so[0].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::INITIAL_JINGLE, + static_cast( + tts_capabilities_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::LISTEN_JINGLE, + static_cast( + tts_capabilities_so[2].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::POSITIVE_JINGLE, + static_cast( + tts_capabilities_so[3].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::NEGATIVE_JINGLE, + static_cast( + tts_capabilities_so[4].asInt())); } } // namespace application_manager_test diff --git a/src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h b/src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h deleted file mode 100644 index 9764a9997f..0000000000 --- a/src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016, 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_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ - -#include "application_manager/hmi_capabilities_impl.h" - -namespace test { -namespace components { -namespace application_manager_test { - -class HMICapabilitiesForTesting - : public ::application_manager::HMICapabilitiesImpl { - public: - HMICapabilitiesForTesting(::application_manager::ApplicationManager& app_mngr) - : HMICapabilitiesImpl(app_mngr) {} - bool LoadCapabilitiesFromFile() { - return load_capabilities_from_file(); - } -}; - -} // namespace application_manager_test -} // namespace components -} // namespace test - -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h index 7c163d78ad..6d428eda24 100644 --- a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h +++ b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h @@ -75,7 +75,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(ui_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_ui_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -85,7 +85,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(vr_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_vr_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -95,7 +95,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(tts_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_tts_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -173,25 +173,25 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { MOCK_METHOD1(set_rc_supported, void(const bool supported)); MOCK_CONST_METHOD0(navigation_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_navigation_capability, void(const smart_objects::SmartObject& navigation_capability)); - MOCK_CONST_METHOD0(phone_capability, const smart_objects::SmartObject*()); + MOCK_CONST_METHOD0(phone_capability, const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_phone_capability, void(const smart_objects::SmartObject& phone_capability)); MOCK_CONST_METHOD0(video_streaming_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1( set_video_streaming_capability, void(const smart_objects::SmartObject& video_streaming_capability)); - MOCK_CONST_METHOD0(rc_capability, const smart_objects::SmartObject*()); + MOCK_CONST_METHOD0(rc_capability, const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_rc_capability, void(const smart_objects::SmartObject& rc_capability)); MOCK_CONST_METHOD0(seat_location_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1( set_seat_location_capability, void(const smart_objects::SmartObject& seat_location_capability)); @@ -203,22 +203,22 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { MOCK_CONST_METHOD0(ccpu_version, const std::string&()); MOCK_METHOD1(set_ccpu_version, void(const std::string& ccpu_version)); + MOCK_METHOD1(OnSoftwareVersionReceived, + void(const std::string& ccpu_version)); + MOCK_METHOD0(UpdateCachedCapabilities, void()); MOCK_METHOD0(get_hmi_language_handler, application_manager::HMILanguageHandler&()); MOCK_METHOD1(set_handle_response_for, void(const smart_objects::SmartObject& request)); - - protected: - MOCK_CONST_METHOD2(check_existing_json_member, - bool(const Json::Value& json_member, - const char* name_of_member)); - - MOCK_CONST_METHOD2(convert_json_languages_to_obj, - void(const Json::Value& json_languages, - smart_objects::SmartObject& languages)); - MOCK_CONST_METHOD2(convert_audio_capability_to_obj, - void(const Json::Value& capability, - smart_objects::SmartObject& output_so)); + MOCK_METHOD3(SaveCachedCapabilitiesToFile, + bool(const std::string& interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema)); + MOCK_CONST_METHOD0(DeleteCachedCapabilitiesFile, bool()); + MOCK_CONST_METHOD1(IsRequestsRequiredForCapabilities, + bool(hmi_apis::FunctionID::eType)); + MOCK_METHOD1(UpdateRequestsRequiredForCapabilities, + void(hmi_apis::FunctionID::eType requested_interface)); }; } // namespace application_manager_test diff --git a/src/components/config_profile/include/config_profile/profile.h b/src/components/config_profile/include/config_profile/profile.h index 76c66c7c7b..bbd0a5d243 100644 --- a/src/components/config_profile/include/config_profile/profile.h +++ b/src/components/config_profile/include/config_profile/profile.h @@ -211,6 +211,12 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, */ const std::string& hmi_capabilities_file_name() const; + /** + * @brief Returns hmi capabilities cache file name + * @return hmi capabilities cache file name + */ + const std::string& hmi_capabilities_cache_file_name() const; + /** * @brief Returns help promt vector */ @@ -985,6 +991,7 @@ class Profile : public protocol_handler::ProtocolHandlerSettings, uint32_t stop_streaming_timeout_; uint16_t time_testing_port_; std::string hmi_capabilities_file_name_; + std::string hmi_capabilities_cache_file_name_; std::vector help_prompt_; std::vector time_out_promt_; std::vector vr_commands_; diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index 3037b66fdd..00fd546a02 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -101,6 +101,7 @@ const char* kRCModuleConsentSection = "RCModuleConsent"; const char* kSDLVersionKey = "SDLVersion"; const char* kHmiCapabilitiesKey = "HMICapabilities"; +const char* kHmiCapabilitiesCacheFileKey = "HMICapabilitiesCacheFile"; const char* kPathToSnapshotKey = "PathToSnapshot"; const char* kPreloadedPTKey = "PreloadedPT"; const char* kAttemptsToOpenPolicyDBKey = "AttemptsToOpenPolicyDB"; @@ -472,6 +473,7 @@ Profile::Profile() , stop_streaming_timeout_(kDefaultStopStreamingTimeout) , time_testing_port_(kDefaultTimeTestingPort) , hmi_capabilities_file_name_(kDefaultHmiCapabilitiesFileName) + , hmi_capabilities_cache_file_name_() , help_prompt_() , time_out_promt_() , min_tread_stack_size_(threads::Thread::kMinStackSize) @@ -650,6 +652,10 @@ const std::string& Profile::hmi_capabilities_file_name() const { return hmi_capabilities_file_name_; } +const std::string& Profile::hmi_capabilities_cache_file_name() const { + return hmi_capabilities_cache_file_name_; +} + const std::string& Profile::server_address() const { return server_address_; } @@ -1335,6 +1341,21 @@ void Profile::UpdateValues() { LOG_UPDATED_VALUE(app_storage_folder_, kAppStorageFolderKey, kMainSection); + // HMI capabilities cache file + ReadStringValue(&hmi_capabilities_cache_file_name_, + "", + kMainSection, + kHmiCapabilitiesCacheFileKey); + + if (!hmi_capabilities_cache_file_name_.empty()) { + hmi_capabilities_cache_file_name_ = + app_storage_folder_ + "/" + hmi_capabilities_cache_file_name_; + } + + LOG_UPDATED_VALUE(hmi_capabilities_cache_file_name_, + kHmiCapabilitiesCacheFileKey, + kMainSection); + // Application resourse folder ReadStringValue(&app_resource_folder_, file_system::CurrentWorkingDirectory().c_str(), diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 9de5b3a143..7245553a18 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -512,7 +512,13 @@ class ApplicationManager { virtual void ConnectToDevice(const std::string& device_mac) = 0; - virtual void OnHMIStartedCooperation() = 0; + virtual void OnHMIReady() = 0; + + /** + * @brief Send GetCapabilities requests for + * each interface (VR, TTS, UI etc) to HMI + */ + virtual void RequestForInterfacesAvailability() = 0; virtual void DisconnectCloudApp(ApplicationSharedPtr app) = 0; @@ -531,6 +537,13 @@ class ApplicationManager { GetCloudAppConnectionStatus(ApplicationConstSharedPtr app) const = 0; virtual bool IsHMICooperating() const = 0; + + /* + * @brief Hold or respond to all pending RAI requests + * @param hmi_cooperating new state to be set + */ + virtual void SetHMICooperating(const bool hmi_cooperating) = 0; + /** * @brief Notifies all components interested in Vehicle Data update * i.e. new value of odometer etc and returns list of applications diff --git a/src/components/include/application_manager/application_manager_settings.h b/src/components/include/application_manager/application_manager_settings.h index 5b3dfc26df..02cd79aa8e 100644 --- a/src/components/include/application_manager/application_manager_settings.h +++ b/src/components/include/application_manager/application_manager_settings.h @@ -76,6 +76,7 @@ class ApplicationManagerSettings : public RequestControlerSettings, virtual const std::vector& time_out_promt() const = 0; virtual const std::vector& help_prompt() const = 0; virtual const std::string& hmi_capabilities_file_name() const = 0; + virtual const std::string& hmi_capabilities_cache_file_name() const = 0; virtual const std::string& video_server_type() const = 0; virtual const std::string& audio_server_type() const = 0; virtual const std::string& server_address() const = 0; diff --git a/src/components/include/application_manager/hmi_capabilities.h b/src/components/include/application_manager/hmi_capabilities.h index e10295b56f..0948a4e6ad 100644 --- a/src/components/include/application_manager/hmi_capabilities.h +++ b/src/components/include/application_manager/hmi_capabilities.h @@ -46,9 +46,8 @@ class ApplicationManager; class HMICapabilities { public: - /* + /** * @brief Class destructor - * */ virtual ~HMICapabilities() {} @@ -59,7 +58,7 @@ class HMICapabilities { */ virtual HMILanguageHandler& get_hmi_language_handler() = 0; - /* + /** * @brief Checks if image type(Static/Dynamic) requested by * Mobile Device is supported on current HMI. * @param image_type received type of image from Enum. @@ -69,7 +68,6 @@ class HMICapabilities { /** * @brief Checks if all HMI capabilities received - * * @return TRUE if all information received, otherwise FALSE */ virtual bool is_vr_cooperating() const = 0; @@ -90,417 +88,369 @@ class HMICapabilities { virtual bool is_rc_cooperating() const = 0; virtual void set_is_rc_cooperating(const bool value) = 0; - /* + /** * @brief Interface used to store information about software version of the - *target - * + * target * @param ccpu_version Received system/hmi software version */ virtual void set_ccpu_version(const std::string& ccpu_version) = 0; - /* + /** * @brief Returns software version of the target - * * @return TRUE if it supported, otherwise FALSE */ virtual const std::string& ccpu_version() const = 0; - /* + /** * @brief Retrieves if mixing audio is supported by HMI * (ie recording TTS command and playing audio) - * * @return Current state of the mixing audio flag */ virtual bool attenuated_supported() const = 0; - /* + /** * @brief Sets state for mixing audio - * * @param state New state to be set */ virtual void set_attenuated_supported(const bool state) = 0; - /* + /** * @brief Retrieves currently active UI language - * * @return Currently active UI language */ virtual const hmi_apis::Common_Language::eType active_ui_language() const = 0; - /* + /** * @brief Sets currently active UI language - * * @param language Currently active UI language */ virtual void set_active_ui_language( const hmi_apis::Common_Language::eType language) = 0; - /* + /** * @brief Retrieves UI supported languages - * * @return Currently supported UI languages */ - virtual const smart_objects::SmartObject* ui_supported_languages() const = 0; + virtual const smart_objects::SmartObjectSPtr ui_supported_languages() + const = 0; - /* + /** * @brief Sets supported UI languages - * * @param supported_languages Supported UI languages */ virtual void set_ui_supported_languages( const smart_objects::SmartObject& supported_languages) = 0; - /* + /** * @brief Retrieves currently active VR language - * * @return Currently active VR language */ virtual const hmi_apis::Common_Language::eType active_vr_language() const = 0; - /* + /** * @brief Sets currently active VR language - * * @param language Currently active VR language */ virtual void set_active_vr_language( const hmi_apis::Common_Language::eType language) = 0; - /* + /** * @brief Retrieves VR supported languages - * * @return Currently supported VR languages */ - virtual const smart_objects::SmartObject* vr_supported_languages() const = 0; + virtual const smart_objects::SmartObjectSPtr vr_supported_languages() + const = 0; - /* + /** * @brief Sets supported VR languages - * * @param supported_languages Supported VR languages */ virtual void set_vr_supported_languages( const smart_objects::SmartObject& supported_languages) = 0; - /* + /** * @brief Retrieves currently active TTS language - * * @return Currently active TTS language */ virtual const hmi_apis::Common_Language::eType active_tts_language() const = 0; - /* + /** * @brief Sets currently active TTS language - * * @param language Currently active TTS language */ virtual void set_active_tts_language( const hmi_apis::Common_Language::eType language) = 0; - /* + /** * @brief Retrieves TTS supported languages - * * @return Currently supported TTS languages */ - virtual const smart_objects::SmartObject* tts_supported_languages() const = 0; + virtual const smart_objects::SmartObjectSPtr tts_supported_languages() + const = 0; - /* + /** * @brief Sets supported TTS languages - * * @param supported_languages Supported TTS languages */ virtual void set_tts_supported_languages( const smart_objects::SmartObject& supported_languages) = 0; - /* + /** * @brief Retrieves information about the display capabilities - * * @return Currently supported display capabilities */ virtual const smart_objects::SmartObjectSPtr display_capabilities() const = 0; - /* + /** * @brief Sets supported display capabilities - * * @param display_capabilities supported display capabilities */ virtual void set_display_capabilities( const smart_objects::SmartObject& display_capabilities) = 0; - /* + /** * @brief Retrieves information about the display capability * @return Currently supported display capability */ virtual const smart_objects::SmartObjectSPtr system_display_capabilities() const = 0; - /* + /** * @brief Sets supported display capability * @param display_capabilities supported display capability */ virtual void set_system_display_capabilities( const smart_objects::SmartObject& display_capabilities) = 0; - /* + /** * @brief Retrieves information about the HMI zone capabilities - * * @return Currently supported HMI zone capabilities */ virtual const smart_objects::SmartObjectSPtr hmi_zone_capabilities() const = 0; - /* + /** * @brief Sets supported HMI zone capabilities - * * @param hmi_zone_capabilities supported HMI zone capabilities */ virtual void set_hmi_zone_capabilities( const smart_objects::SmartObject& hmi_zone_capabilities) = 0; - /* + /** * @brief Retrieves information about the SoftButton's capabilities - * * @return Currently supported SoftButton's capabilities */ virtual const smart_objects::SmartObjectSPtr soft_button_capabilities() const = 0; - /* + /** * @brief Sets supported SoftButton's capabilities - * * @param soft_button_capabilities supported SoftButton's capabilities */ virtual void set_soft_button_capabilities( const smart_objects::SmartObject& soft_button_capabilities) = 0; - /* + /** * @brief Retrieves information about the Button's capabilities - * * @return Currently supported Button's capabilities */ virtual const smart_objects::SmartObjectSPtr button_capabilities() const = 0; - /* + /** * @brief Sets supported Button's capabilities - * * @param soft_button_capabilities supported Button's capabilities */ virtual void set_button_capabilities( const smart_objects::SmartObject& button_capabilities) = 0; - /* + /** * @brief Sets supported speech capabilities - * * @param speech_capabilities supported speech capabilities */ virtual void set_speech_capabilities( const smart_objects::SmartObject& speech_capabilities) = 0; - /* + /** * @brief Retrieves information about the speech capabilities - * * @return Currently supported speech capabilities */ virtual const smart_objects::SmartObjectSPtr speech_capabilities() const = 0; - /* + /** * @brief Sets supported VR capabilities - * * @param vr_capabilities supported VR capabilities */ virtual void set_vr_capabilities( const smart_objects::SmartObject& vr_capabilities) = 0; - /* + /** * @brief Retrieves information about the VR capabilities - * * @return Currently supported VR capabilities */ virtual const smart_objects::SmartObjectSPtr vr_capabilities() const = 0; - /* + /** * @brief Sets supported audio_pass_thru capabilities - * * @param vr_capabilities supported audio_pass_thru capabilities */ virtual void set_audio_pass_thru_capabilities( const smart_objects::SmartObject& audio_pass_thru_capabilities) = 0; - /* + /** * @brief Retrieves information about the audio_pass_thru capabilities - * * @return Currently supported audio_pass_thru capabilities */ virtual const smart_objects::SmartObjectSPtr audio_pass_thru_capabilities() const = 0; - /* + /** * @brief Sets supported pcm_stream capabilities - * * @param supported pcm_stream capabilities */ virtual void set_pcm_stream_capabilities( const smart_objects::SmartObject& pcm_stream_capabilities) = 0; - /* + /** * @brief Retrieves information about the pcm_stream capabilities - * * @return Currently supported pcm_streaming capabilities */ virtual const smart_objects::SmartObjectSPtr pcm_stream_capabilities() const = 0; - /* + /** * @brief Retrieves information about the preset bank capabilities - * * @return Currently supported preset bank capabilities */ virtual const smart_objects::SmartObjectSPtr preset_bank_capabilities() const = 0; - /* + /** * @brief Sets supported preset bank capabilities - * * @param soft_button_capabilities supported preset bank capabilities */ virtual void set_preset_bank_capabilities( const smart_objects::SmartObject& preset_bank_capabilities) = 0; - /* + /** * @brief Sets vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information + * @param vehicle_type vehicle information */ virtual void set_vehicle_type( const smart_objects::SmartObject& vehicle_type) = 0; - /* + /** * @brief Retrieves vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information + * @param vehicle_type Current vehicle information */ virtual const smart_objects::SmartObjectSPtr vehicle_type() const = 0; - /* + /** * @brief Retrieves information about the prerecorded speech - * * @return Currently supported prerecorded speech */ virtual const smart_objects::SmartObjectSPtr prerecorded_speech() const = 0; - /* + /** * @brief Sets supported prerecorded speech - * * @param prerecorded_speech supported prerecorded speech */ virtual void set_prerecorded_speech( const smart_objects::SmartObject& prerecorded_speech) = 0; - /* + /** * @brief Interface used to store information if navigation * supported by the system - * * @param supported Indicates if navigation supported by the system */ virtual void set_navigation_supported(const bool supported) = 0; - /* + /** * @brief Retrieves information if navi supported by the system - * * @return TRUE if it supported, otherwise FALSE */ virtual bool navigation_supported() const = 0; - /* + /** * @brief Interface used to store information if phone call * supported by the system - * * @param supported Indicates if navigation supported by the sustem */ virtual void set_phone_call_supported(const bool supported) = 0; - /* + /** * @brief Retrieves information if phone call supported by the system - * * @return TRUE if it supported, otherwise FALSE */ virtual bool phone_call_supported() const = 0; - /* + /** * @brief Interface to store whether HMI supports video streaming - * * @param supported Indicates whether video streaming is supported by HMI */ virtual void set_video_streaming_supported(const bool supported) = 0; - /* + /** * @brief Retrieves whether HMI supports video streaming - * * @return TRUE if it supported, otherwise FALSE */ virtual bool video_streaming_supported() const = 0; - /* + /** * @brief Interface to store whether HMI supports remote control - * - * @param supported Indicates whether remote control is supported by HMI + * @param supported Indicates whether video streaming is supported by HMI */ virtual void set_rc_supported(const bool supported) = 0; - /* + /** * @brief Retrieves whether HMI supports remote control - * * @return TRUE if it supported, otherwise FALSE */ virtual bool rc_supported() const = 0; - /* + /** * @brief Interface used to store information regarding * the navigation "System Capability" - * * @param navigation_capability contains information related * to the navigation system capability. */ virtual void set_navigation_capability( const smart_objects::SmartObject& navigation_capability) = 0; - /* + /** * @brief Retrieves information regarding the navigation system capability - * * @return NAVIGATION system capability */ - virtual const smart_objects::SmartObject* navigation_capability() const = 0; + virtual const smart_objects::SmartObjectSPtr navigation_capability() + const = 0; - /* + /** * @brief Interface used to store information regarding * the phone "System Capability" - * * @param phone_capability contains information related * to the phone system capability. */ virtual void set_phone_capability( const smart_objects::SmartObject& phone_capability) = 0; - /* + /** * @brief Retrieves information regarding the phone call system capability - * * @return PHONE_CALL system capability */ - virtual const smart_objects::SmartObject* phone_capability() const = 0; + virtual const smart_objects::SmartObjectSPtr phone_capability() const = 0; - /* + /** * @brief Sets HMI's video streaming related capability information - * * @param video_streaming_capability the video streaming related capabilities */ virtual void set_video_streaming_capability( const smart_objects::SmartObject& video_streaming_capability) = 0; - /* + /** * @brief Retrieves HMI's video streaming related capabilities - * * @return HMI's video streaming related capability information */ - virtual const smart_objects::SmartObject* video_streaming_capability() + virtual const smart_objects::SmartObjectSPtr video_streaming_capability() const = 0; /** @@ -510,7 +460,11 @@ class HMICapabilities { virtual void set_rc_capability( const smart_objects::SmartObject& rc_capability) = 0; - virtual const smart_objects::SmartObject* rc_capability() const = 0; + /** + * @brief Retrieves information regarding the remote control capabilities + * @return RC capabilities + */ + virtual const smart_objects::SmartObjectSPtr rc_capability() const = 0; /** * @brief Sets available SeatLocation capabilities for further usage by @@ -525,7 +479,7 @@ class HMICapabilities { * seat location capability * @return smart object of seat location capability */ - virtual const smart_objects::SmartObject* seat_location_capability() + virtual const smart_objects::SmartObjectSPtr seat_location_capability() const = 0; DEPRECATED @@ -540,35 +494,53 @@ class HMICapabilities { virtual void set_handle_response_for( const smart_objects::SmartObject& request) = 0; - protected: - /* - * @brief function checks if json member exists - * - * @param json_member from file hmi_capabilities.json - * @param name_of_member name which we should check - * hmi_capabilities.json - * - * @returns TRUE if member exists and returns FALSE if - * member does not exist. - */ - virtual bool check_existing_json_member(const Json::Value& json_member, - const char* name_of_member) const = 0; - - virtual void convert_json_languages_to_obj( - const Json::Value& json_languages, - smart_objects::SmartObject& languages) const = 0; - - /* - * @brief function that converts a single entry of audio pass thru capability - * to smart object - * - * @param capability json object that represents a single entry of audio pass - * thru capability - * @param output_so the converted object - */ - virtual void convert_audio_capability_to_obj( - const Json::Value& capability, - smart_objects::SmartObject& output_so) const = 0; + /** + * @brief Writes cached HMI capabilities from internal cache into the file if + * any of updated sections are not present in the file + * @param interface_name name of interface to be updated + * @param sections_to_update vector of names of sections which were updated in + * cache + * @param schema reference to schema which should be unapplied before saving + * stringified JSON data into the file + * @return true if cache was saved successfully, otherwise returns false + */ + virtual bool SaveCachedCapabilitiesToFile( + const std::string& interface_name, + const std::vector& sections_to_update, + const smart_objects::CSmartSchema& schema) = 0; + + /** + * @brief Deletes cached HMI capabilities file from a file system + */ + virtual bool DeleteCachedCapabilitiesFile() const = 0; + + /** + * @brief Checks if request required for appropriate function id + * @param function_id function ID that required request to get appropriate hmi + * capabilities + * @return true if request required for capabilities, otherwise false + */ + virtual bool IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType function_id) const = 0; + + /** + * @brief Update collection of requests that should be send to + * the HMI to get required HMI capabilities + * @param requested_interface function id + */ + virtual void UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) = 0; + + /** + * @brief Interface that update capabilities depending on ccpu_version + * @param ccpu_version Received system/hmi software version + */ + virtual void OnSoftwareVersionReceived(const std::string& ccpu_version) = 0; + + /** + * @brief Interface that update cached hmi capabilities + */ + virtual void UpdateCachedCapabilities() = 0; }; } // namespace application_manager diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index 1c039d6a88..24d6db0d65 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -315,6 +315,12 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { */ virtual void OnSystemInfoChanged(const std::string& language) = 0; + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + virtual void SetPreloadedPtFlag(const bool is_preloaded) = 0; + /** * @brief Save data from GetSystemInfo request to policy table * @param ccpu_version CCPU version @@ -325,6 +331,12 @@ class PolicyHandlerInterface : public VehicleDataItemProvider { const std::string& wers_country_code, const std::string& language) = 0; + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + virtual std::string GetCCPUVersionFromPT() const = 0; + /** * @brief Sends GetVehicleData request in case when Vechicle info is ready. */ diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 02810038c3..184b3049f5 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -416,6 +416,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, */ virtual void SetSystemLanguage(const std::string& language) = 0; + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + virtual void SetPreloadedPtFlag(const bool is_preloaded) = 0; + /** * @brief Set data from GetSystemInfo response to policy table * @param ccpu_version CCPU version @@ -426,6 +432,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, const std::string& wers_country_code, const std::string& language) = 0; + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + virtual std::string GetCCPUVersionFromPT() const = 0; + /** * @brief Send OnPermissionsUpdated for choosen application * @param device_id device identifier diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index 99f38673ef..cc7fc1e1ce 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -407,6 +407,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, */ virtual void SetSystemLanguage(const std::string& language) = 0; + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + virtual void SetPreloadedPtFlag(const bool is_preloaded) = 0; + /** * @brief Set data from GetSystemInfo response to policy table * @param ccpu_version CCPU version @@ -417,6 +423,12 @@ class PolicyManager : public usage_statistics::StatisticsManager, const std::string& wers_country_code, const std::string& language) = 0; + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + virtual std::string GetCCPUVersionFromPT() const = 0; + /** * @brief Send OnPermissionsUpdated for choosen application * @param device_id device identifier 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 cd15caf7a5..ca72c18229 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -205,7 +205,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD1(BeginAudioPassThru, bool(uint32_t app_id)); MOCK_METHOD1(EndAudioPassThru, bool(uint32_t app_id)); MOCK_METHOD1(ConnectToDevice, void(const std::string& device_mac)); - MOCK_METHOD0(OnHMIStartedCooperation, void()); + MOCK_METHOD0(OnHMIReady, void()); + MOCK_METHOD0(RequestForInterfacesAvailability, void()); MOCK_METHOD1(DisconnectCloudApp, void(application_manager::ApplicationSharedPtr app)); MOCK_METHOD0(RefreshCloudAppInformation, void()); @@ -215,6 +216,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD1(PolicyIDByIconUrl, std::string(const std::string url)); MOCK_METHOD1(SetIconFileFromSystemRequest, void(const std::string policy_id)); MOCK_CONST_METHOD0(IsHMICooperating, bool()); + MOCK_METHOD1(SetHMICooperating, void(const bool hmi_cooperating)); MOCK_METHOD2(IviInfoUpdated, void(const std::string& vehicle_info, int value)); MOCK_METHOD1(RegisterApplication, diff --git a/src/components/include/test/application_manager/mock_application_manager_settings.h b/src/components/include/test/application_manager/mock_application_manager_settings.h index 1a68d663fe..9a70a374a7 100644 --- a/src/components/include/test/application_manager/mock_application_manager_settings.h +++ b/src/components/include/test/application_manager/mock_application_manager_settings.h @@ -82,6 +82,7 @@ class MockApplicationManagerSettings MOCK_CONST_METHOD0(help_prompt, const std::vector&()); MOCK_CONST_METHOD0(time_out_promt, const std::vector&()); MOCK_CONST_METHOD0(hmi_capabilities_file_name, const std::string&()); + MOCK_CONST_METHOD0(hmi_capabilities_cache_file_name, const std::string&()); MOCK_CONST_METHOD0(video_server_type, const std::string&()); MOCK_CONST_METHOD0(audio_server_type, const std::string&()); MOCK_CONST_METHOD0(server_address, const std::string&()); diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index 38c1cca69e..d52daa8fca 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -180,10 +180,12 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { std::string(const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id)); MOCK_METHOD1(OnSystemInfoChanged, void(const std::string& language)); + MOCK_METHOD1(SetPreloadedPtFlag, void(const bool is_preloaded)); MOCK_METHOD3(OnGetSystemInfo, void(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language)); + MOCK_CONST_METHOD0(GetCCPUVersionFromPT, std::string()); MOCK_METHOD0(OnVIIsReady, void()); MOCK_METHOD1(OnVehicleDataUpdated, void(const smart_objects::SmartObject& message)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index c7a6e3d50a..61022035bc 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -202,10 +202,12 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD2(SetUserPermissionsForApp, bool(const PermissionConsent& permissions, bool* out_app_permissions_changed)); + MOCK_METHOD1(SetPreloadedPtFlag, void(const bool is_preloaded)); MOCK_METHOD3(SetMetaInfo, bool(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language)); + MOCK_CONST_METHOD0(GetCCPUVersionFromPT, std::string()); MOCK_CONST_METHOD0(IsMetaInfoPresent, bool()); MOCK_METHOD1(SetSystemLanguage, bool(const std::string& language)); MOCK_METHOD1(Increment, void(usage_statistics::GlobalCounterId type)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index bf092d38e8..28a895fa64 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -173,6 +173,7 @@ class MockPolicyManager : public PolicyManager { void(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language)); + MOCK_METHOD1(SetPreloadedPtFlag, void(const bool is_preloaded)); MOCK_METHOD2(SendNotificationOnPermissionsUpdated, void(const std::string& device_id, const std::string& application_id)); @@ -305,6 +306,7 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD0(OnSystemRequestReceived, void()); MOCK_METHOD0(RetrySequenceFailed, void()); MOCK_METHOD0(ResetTimeout, void()); + MOCK_CONST_METHOD0(GetCCPUVersionFromPT, std::string()); }; } // namespace policy_manager_test } // namespace components diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index d8e13b4b2e..97915884d7 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -176,10 +176,12 @@ class MockCacheManagerInterface : public CacheManagerInterface { bool(const std::string& app_id, bool is_device_allowed)); MOCK_METHOD1(SetUserPermissionsForApp, bool(const PermissionConsent& permissions)); + MOCK_METHOD1(SetPreloadedPtFlag, void(const bool is_preloaded)); MOCK_METHOD3(SetMetaInfo, bool(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language)); + MOCK_CONST_METHOD0(GetCCPUVersionFromPT, std::string()); MOCK_CONST_METHOD0(IsMetaInfoPresent, bool()); MOCK_METHOD1(SetSystemLanguage, bool(const std::string& language)); MOCK_METHOD1(Increment, void(usage_statistics::GlobalCounterId type)); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index ac0fab4328..97f4504f71 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -172,6 +172,7 @@ class MockPolicyManager : public PolicyManager { void(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language)); + MOCK_METHOD1(SetPreloadedPtFlag, void(const bool is_preloaded)); MOCK_METHOD2(SendNotificationOnPermissionsUpdated, void(const std::string& device_id, const std::string& application_id)); @@ -308,6 +309,7 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD1(GetAppRequestSubTypesState, RequestSubType::State(const std::string& policy_app_id)); MOCK_METHOD0(ResetTimeout, void()); + MOCK_CONST_METHOD0(GetCCPUVersionFromPT, std::string()); }; } // namespace policy_manager_test diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index b826f4e5ce..36dd6d7259 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -596,6 +596,12 @@ class CacheManager : public CacheManagerInterface { bool SetUserPermissionsForApp(const PermissionConsent& permissions, bool* out_app_permissions_changed); + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + /** * @brief Records information about head unit system to PT * @return bool Success of operation @@ -604,6 +610,12 @@ class CacheManager : public CacheManagerInterface { const std::string& wers_country_code, const std::string& language); + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + std::string GetCCPUVersionFromPT() const; + /** * @brief Checks, if specific head unit is present in PT * @return boot Suceess, if present, otherwise - false diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index 3e3de694d6..44df1f36a5 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -637,6 +637,12 @@ class CacheManagerInterface { virtual bool SetUserPermissionsForApp(const PermissionConsent& permissions, bool* out_app_permissions_changed) = 0; + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + virtual void SetPreloadedPtFlag(const bool is_preloaded) = 0; + /** * @brief Records information about head unit system to PT * @return bool Success of operation @@ -645,6 +651,12 @@ class CacheManagerInterface { const std::string& wers_country_code, const std::string& language) = 0; + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + virtual std::string GetCCPUVersionFromPT() const = 0; + /** * @brief Checks, if specific head unit is present in PT * @return boot Suceess, if present, otherwise - false diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 5c55be50d1..04fac53885 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -435,6 +435,10 @@ class PolicyManagerImpl : public PolicyManager { const std::string& wers_country_code, const std::string& language) OVERRIDE; + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + + std::string GetCCPUVersionFromPT() const OVERRIDE; + /** * @brief Get number of notification by priority * @param priority Specified priority diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index 11c76bdd68..6e6fd1afb8 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -485,7 +485,7 @@ struct ConsumerFriendlyMessages : CompositeType { struct ModuleMeta : CompositeType { public: - Optional > ccpu_version; + Optional > ccpu_version; Optional > language; Optional > wers_country_code; Optional > pt_exchanged_at_odometer_x; diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index d8819b6bad..40c216a720 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -2275,6 +2275,12 @@ int CacheManager::CountUnconsentedGroups(const std::string& policy_app_id, return result; } +void CacheManager::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + *pt_->policy_table.module_config.preloaded_pt = is_preloaded; + Backup(); +} + bool CacheManager::SetMetaInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { @@ -2293,6 +2299,13 @@ bool CacheManager::SetMetaInfo(const std::string& ccpu_version, return true; } +std::string CacheManager::GetCCPUVersionFromPT() const { + LOG4CXX_AUTO_TRACE(logger_); + rpc::Optional& module_meta = + pt_->policy_table.module_meta; + return *(module_meta->ccpu_version); +} + bool CacheManager::IsMetaInfoPresent() const { CACHE_MANAGER_CHECK(false); bool result = true; diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 12ab1224fd..f057e21617 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -1623,6 +1623,11 @@ void PolicyManagerImpl::SetSystemLanguage(const std::string& language) { cache_->SetSystemLanguage(language); } +void PolicyManagerImpl::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + cache_->SetPreloadedPtFlag(is_preloaded); +} + void PolicyManagerImpl::SetSystemInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { @@ -1630,6 +1635,11 @@ void PolicyManagerImpl::SetSystemInfo(const std::string& ccpu_version, cache_->SetMetaInfo(ccpu_version, wers_country_code, language); } +std::string PolicyManagerImpl::GetCCPUVersionFromPT() const { + LOG4CXX_AUTO_TRACE(logger_); + return cache_->GetCCPUVersionFromPT(); +} + uint32_t PolicyManagerImpl::GetNotificationsNumber( const std::string& priority) const { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index 00f0adab06..053d4dc807 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -543,6 +543,12 @@ class CacheManager : public CacheManagerInterface { */ bool SetUserPermissionsForApp(const PermissionConsent& permissions); + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + /** * @brief Records information about head unit system to PT * @return bool Success of operation @@ -551,6 +557,12 @@ class CacheManager : public CacheManagerInterface { const std::string& wers_country_code, const std::string& language); + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + std::string GetCCPUVersionFromPT() const; + /** * @brief Checks, if specific head unit is present in PT * @return boot Suceess, if present, otherwise - false diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index fc1a6337aa..f161724671 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -578,6 +578,12 @@ class CacheManagerInterface { virtual bool SetUserPermissionsForApp( const PermissionConsent& permissions) = 0; + /** + * @brief Set preloaded_pt flag value in policy table + * @param is_preloaded value to set + */ + virtual void SetPreloadedPtFlag(const bool is_preloaded) = 0; + /** * @brief Records information about head unit system to PT * @return bool Success of operation @@ -586,6 +592,12 @@ class CacheManagerInterface { const std::string& wers_country_code, const std::string& language) = 0; + /** + * @brief Get information about last ccpu_version from PT + * @return ccpu_version from PT + */ + virtual std::string GetCCPUVersionFromPT() const = 0; + /** * @brief Checks, if specific head unit is present in PT * @return boot Suceess, if present, otherwise - false diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index aa77019613..1b87e58310 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -451,6 +451,10 @@ class PolicyManagerImpl : public PolicyManager { const std::string& wers_country_code, const std::string& language) OVERRIDE; + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + + std::string GetCCPUVersionFromPT() const OVERRIDE; + /** * @brief Get number of notification by priority * @param priority Specified priority diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index 2ffbf2e7ec..1c6442501f 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -427,6 +427,7 @@ struct ModuleMeta : CompositeType { Optional > pt_exchanged_at_odometer_x; Optional > pt_exchanged_x_days_after_epoch; Optional > ignition_cycles_since_last_exchange; + Optional > ccpu_version; public: ModuleMeta(); diff --git a/src/components/policy/policy_regular/include/policy/pt_representation.h b/src/components/policy/policy_regular/include/policy/pt_representation.h index 467fb4641f..895b4ea6b5 100644 --- a/src/components/policy/policy_regular/include/policy/pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/pt_representation.h @@ -151,6 +151,12 @@ class PTRepresentation { */ virtual EndpointUrls GetUpdateUrls(int service_type) = 0; + /** + * @brief Records information about head unit system to PT + * @return bool Success of operation + */ + virtual bool SetMetaInfo(const std::string& ccpu_version) = 0; + /** * @brief Get allowed number of notifications * depending on application priority. diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h index 315c30b995..0b0ae11f3f 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h @@ -142,6 +142,7 @@ extern const std::string kSelectDBVersion; extern const std::string kUpdateDBVersion; extern const std::string kSaveModuleMeta; extern const std::string kSelectModuleMeta; +extern const std::string kUpdateMetaParams; extern const std::string kInsertVehicleDataItem; extern const std::string kSelectVehicleDataItem; extern const std::string kDeleteVehicleDataItems; diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h index 1bb74e028c..eeeaeed2cd 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h @@ -90,7 +90,7 @@ class SQLPTRepresentation : public virtual PTRepresentation { StringArray* nicknames = NULL, StringArray* app_hmi_types = NULL); bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups); - + bool SetMetaInfo(const std::string& ccpu_version); #ifdef BUILD_TESTS uint32_t open_counter() { return open_counter_; diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 28ceec3ccb..75f0e72113 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -1346,6 +1346,8 @@ void CacheManager::PersistData() { is_revoked = false; } + backup_->SetMetaInfo(*(*copy_pt.policy_table.module_meta).ccpu_version); + // In case of extended policy the meta info should be backuped as well. backup_->WriteDb(); } @@ -1479,20 +1481,34 @@ int CacheManager::CountUnconsentedGroups(const std::string& policy_app_id, return result; } +void CacheManager::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + *(pt_->policy_table.module_config.preloaded_pt) = is_preloaded; + Backup(); +} + bool CacheManager::SetMetaInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { CACHE_MANAGER_CHECK(false); sync_primitives::AutoLock auto_lock(cache_lock_); - + rpc::Optional& module_meta = + pt_->policy_table.module_meta; + *(module_meta->ccpu_version) = ccpu_version; // We have to set preloaded flag as false in policy table on any response // of GetSystemInfo (SDLAQ-CRS-2365) - *pt_->policy_table.module_config.preloaded_pt = false; - + *(pt_->policy_table.module_config.preloaded_pt) = false; Backup(); return true; } +std::string CacheManager::GetCCPUVersionFromPT() const { + LOG4CXX_AUTO_TRACE(logger_); + rpc::Optional& module_meta = + pt_->policy_table.module_meta; + return *(module_meta->ccpu_version); +} + bool CacheManager::IsMetaInfoPresent() const { CACHE_MANAGER_CHECK(false); bool result = true; diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 0cdca26f2e..b40d71dd73 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -1214,10 +1214,21 @@ std::string& PolicyManagerImpl::GetCurrentDeviceId( void PolicyManagerImpl::SetSystemLanguage(const std::string& language) {} +void PolicyManagerImpl::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + cache_->SetPreloadedPtFlag(is_preloaded); +} + void PolicyManagerImpl::SetSystemInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { LOG4CXX_AUTO_TRACE(logger_); + cache_->SetMetaInfo(ccpu_version, wers_country_code, language); +} + +std::string PolicyManagerImpl::GetCCPUVersionFromPT() const { + LOG4CXX_AUTO_TRACE(logger_); + return cache_->GetCCPUVersionFromPT(); } uint32_t PolicyManagerImpl::GetNotificationsNumber( diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 3029ebb067..1c7d06dedf 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -1274,7 +1274,8 @@ ModuleMeta::ModuleMeta(const Json::Value* value__) , pt_exchanged_x_days_after_epoch( impl::ValueMember(value__, "pt_exchanged_x_days_after_epoch")) , ignition_cycles_since_last_exchange( - impl::ValueMember(value__, "ignition_cycles_since_last_exchange")) {} + impl::ValueMember(value__, "ignition_cycles_since_last_exchange")) + , ccpu_version(impl::ValueMember(value__, "ccpu_version")) {} Json::Value ModuleMeta::ToJsonValue() const { Json::Value result__(Json::objectValue); @@ -1293,6 +1294,9 @@ bool ModuleMeta::is_valid() const { if (struct_empty()) { return initialization_state__ == kInitialized && Validate(); } + if (!ccpu_version.is_valid()) { + return false; + } if (!pt_exchanged_at_odometer_x.is_valid()) { return false; } @@ -1310,6 +1314,9 @@ bool ModuleMeta::is_initialized() const { } bool ModuleMeta::struct_empty() const { + if (ccpu_version.is_initialized()) { + return false; + } if (pt_exchanged_at_odometer_x.is_initialized()) { return false; } @@ -1327,6 +1334,9 @@ void ModuleMeta::ReportErrors(rpc::ValidationReport* report__) const { if (struct_empty()) { rpc::CompositeType::ReportErrors(report__); } + if (!ccpu_version.is_valid()) { + ccpu_version.ReportErrors(&report__->ReportSubobject("ccpu_version")); + } if (!pt_exchanged_at_odometer_x.is_valid()) { pt_exchanged_at_odometer_x.ReportErrors( &report__->ReportSubobject("pt_exchanged_at_odometer_x")); diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index 79eee10d43..7aa853fd74 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -59,7 +59,8 @@ const std::string kCreateSchema = " `pt_exchanged_at_odometer_x` INTEGER NOT NULL DEFAULT 0, " " `pt_exchanged_x_days_after_epoch` INTEGER NOT NULL DEFAULT 0, " " `ignition_cycles_since_last_exchange` INTEGER NOT NULL DEFAULT 0, " - " `flag_update_required` BOOL NOT NULL " + " `flag_update_required` BOOL NOT NULL, " + " `ccpu_version` VARCHAR(45) " "); " "CREATE TABLE IF NOT EXISTS `module_config`( " " `preloaded_pt` BOOL NOT NULL, " @@ -1047,5 +1048,9 @@ const std::string kSaveModuleMeta = "`ignition_cycles_since_last_exchange` = ? "; const std::string kSelectModuleMeta = "SELECT* FROM `module_meta`"; + +const std::string kUpdateMetaParams = + "UPDATE `module_meta` SET " + "`ccpu_version` = ? "; } // namespace sql_pt } // namespace policy diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index ed5bf37b5b..bd4dc6e2c2 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -493,6 +493,7 @@ void SQLPTRepresentation::GatherModuleMeta( *meta->pt_exchanged_at_odometer_x = query.GetInteger(0); *meta->pt_exchanged_x_days_after_epoch = query.GetInteger(1); *meta->ignition_cycles_since_last_exchange = query.GetInteger(2); + *meta->ccpu_version = query.GetString(4); } } @@ -707,6 +708,23 @@ bool SQLPTRepresentation::GatherConsumerFriendlyMessages( return true; } +bool SQLPTRepresentation::SetMetaInfo(const std::string& ccpu_version) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kUpdateMetaParams)) { + LOG4CXX_WARN(logger_, "Incorrect statement for insert to module meta."); + return false; + } + + query.Bind(0, ccpu_version); + + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert to module meta."); + return false; + } + return true; +} + bool SQLPTRepresentation::GatherApplicationPoliciesSection( policy_table::ApplicationPoliciesSection* policies) const { LOG4CXX_INFO(logger_, "Gather applications policies"); diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc index 1cd2ca305e..d5a66f4388 100644 --- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc +++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc @@ -75,12 +75,12 @@ class PolicyManagerImplTest : public ::testing::Test { public: PolicyManagerImplTest() : policy_manager_(nullptr) - , cache_manager_(nullptr) + , mock_cache_manager_(nullptr) , access_remote_(nullptr) {} protected: std::shared_ptr policy_manager_; - NiceMock* cache_manager_; + NiceMock* mock_cache_manager_; NiceMock listener_; NiceMock policy_settings_; std::shared_ptr > @@ -88,8 +88,8 @@ class PolicyManagerImplTest : public ::testing::Test { void SetUp() { policy_manager_ = std::make_shared(); - cache_manager_ = new NiceMock(); - policy_manager_->set_cache_manager(cache_manager_); + mock_cache_manager_ = new NiceMock(); + policy_manager_->set_cache_manager(mock_cache_manager_); policy_manager_->set_listener(&listener_); access_remote_ = std::make_shared >(); @@ -116,7 +116,8 @@ TEST_F(PolicyManagerImplTest, InitPT_NoAppStorageFolder_ReturnFalse) { TEST_F(PolicyManagerImplTest, InitPT_InitializationNotSuccessful_ReturnFalse) { file_system::CreateDirectory(kAppStorageFolder); - EXPECT_CALL(*cache_manager_, Init(kSdlPreloadedPtJson, &policy_settings_)) + EXPECT_CALL(*mock_cache_manager_, + Init(kSdlPreloadedPtJson, &policy_settings_)) .WillOnce(Return(false)); EXPECT_FALSE(policy_manager_->InitPT(kSdlPreloadedPtJson, &policy_settings_)); file_system::RemoveDirectory(kAppStorageFolder, true); @@ -124,28 +125,29 @@ TEST_F(PolicyManagerImplTest, InitPT_InitializationNotSuccessful_ReturnFalse) { TEST_F(PolicyManagerImplTest, InitPT_InitializationIsSuccessful_ReturnTrue) { file_system::CreateDirectory(kAppStorageFolder); - EXPECT_CALL(*cache_manager_, Init(kSdlPreloadedPtJson, &policy_settings_)) + EXPECT_CALL(*mock_cache_manager_, + Init(kSdlPreloadedPtJson, &policy_settings_)) .WillOnce(Return(true)); EXPECT_TRUE(policy_manager_->InitPT(kSdlPreloadedPtJson, &policy_settings_)); file_system::RemoveDirectory(kAppStorageFolder, true); } TEST_F(PolicyManagerImplTest, ResetPT_NoRefreshRetrySequence_ReturnFalse) { - EXPECT_CALL(*cache_manager_, ResetCalculatedPermissions()); - EXPECT_CALL(*cache_manager_, ResetPT(kSdlPreloadedPtJson)) + EXPECT_CALL(*mock_cache_manager_, ResetCalculatedPermissions()); + EXPECT_CALL(*mock_cache_manager_, ResetPT(kSdlPreloadedPtJson)) .WillOnce(Return(false)); - EXPECT_CALL(*cache_manager_, TimeoutResponse()).Times(0); - EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_)).Times(0); + EXPECT_CALL(*mock_cache_manager_, TimeoutResponse()).Times(0); + EXPECT_CALL(*mock_cache_manager_, SecondsBetweenRetries(_)).Times(0); EXPECT_FALSE(policy_manager_->ResetPT(kSdlPreloadedPtJson)); } TEST_F(PolicyManagerImplTest, ResetPT_ExecuteRefreshRetrySequence_ReturnTrue) { - EXPECT_CALL(*cache_manager_, ResetCalculatedPermissions()); - EXPECT_CALL(*cache_manager_, ResetPT(kSdlPreloadedPtJson)) + EXPECT_CALL(*mock_cache_manager_, ResetCalculatedPermissions()); + EXPECT_CALL(*mock_cache_manager_, ResetPT(kSdlPreloadedPtJson)) .WillOnce(Return(true)); - EXPECT_CALL(*cache_manager_, TimeoutResponse()); - EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_)); + EXPECT_CALL(*mock_cache_manager_, TimeoutResponse()); + EXPECT_CALL(*mock_cache_manager_, SecondsBetweenRetries(_)); EXPECT_TRUE(policy_manager_->ResetPT(kSdlPreloadedPtJson)); } @@ -154,7 +156,7 @@ TEST_F(PolicyManagerImplTest, AppNeedEncryption_EncryptionNotRequired_ReturnFalse) { EncryptionRequired encryption_required; *encryption_required = false; - EXPECT_CALL(*cache_manager_, GetAppEncryptionRequiredFlag(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, GetAppEncryptionRequiredFlag(kValidAppId)) .WillOnce(Return(encryption_required)); EXPECT_FALSE(policy_manager_->AppNeedEncryption(kValidAppId)); @@ -163,7 +165,7 @@ TEST_F(PolicyManagerImplTest, TEST_F(PolicyManagerImplTest, AppNeedEncryption_EncryptionNotInitialized_ReturnTrue) { EncryptionRequired encryption_required; - EXPECT_CALL(*cache_manager_, GetAppEncryptionRequiredFlag(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, GetAppEncryptionRequiredFlag(kValidAppId)) .WillOnce(Return(encryption_required)); EXPECT_TRUE(policy_manager_->AppNeedEncryption(kValidAppId)); @@ -171,7 +173,7 @@ TEST_F(PolicyManagerImplTest, TEST_F(PolicyManagerImplTest, FunctionGroupNeedEncryption_NoGroups_ReturnFalse) { - EXPECT_CALL(*cache_manager_, GetFunctionalGroupings(_)); + EXPECT_CALL(*mock_cache_manager_, GetFunctionalGroupings(_)); const std::string absent_group("Base-6"); EXPECT_FALSE(policy_manager_->FunctionGroupNeedEncryption(absent_group)); @@ -184,7 +186,7 @@ TEST_F(PolicyManagerImplTest, const RPCParams params; CheckPermissionResult result; - EXPECT_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillOnce(Return(false)); policy_manager_->CheckPermissions( @@ -200,7 +202,7 @@ TEST_F(PolicyManagerImplTest, CheckPermissionResult result; Strings groups; - ON_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillByDefault(Return(true)); ON_CALL(*access_remote_, IsAppRemoteControl(_)).WillByDefault(Return(true)); ON_CALL(*access_remote_, GetGroups(_)).WillByDefault(ReturnRef(groups)); @@ -218,10 +220,10 @@ TEST_F(PolicyManagerImplTest, CheckPermissionResult result; Strings groups; - ON_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillByDefault(Return(true)); - ON_CALL(*cache_manager_, GetGroups(_)).WillByDefault(ReturnRef(groups)); - ON_CALL(*cache_manager_, IsApplicationRevoked(kValidAppId)) + ON_CALL(*mock_cache_manager_, GetGroups(_)).WillByDefault(ReturnRef(groups)); + ON_CALL(*mock_cache_manager_, IsApplicationRevoked(kValidAppId)) .WillByDefault(Return(true)); policy_manager_->CheckPermissions( @@ -238,10 +240,10 @@ TEST_F(PolicyManagerImplTest, CheckPermissionResult result; Strings groups; - ON_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillByDefault(Return(true)); - ON_CALL(*cache_manager_, GetGroups(_)).WillByDefault(ReturnRef(groups)); - ON_CALL(*cache_manager_, IsApplicationRevoked(kValidAppId)) + ON_CALL(*mock_cache_manager_, GetGroups(_)).WillByDefault(ReturnRef(groups)); + ON_CALL(*mock_cache_manager_, IsApplicationRevoked(kValidAppId)) .WillByDefault(Return(true)); policy_manager_->CheckPermissions( @@ -255,7 +257,7 @@ TEST_F( GetPermissionsForApp_CannotGetPermissionsForRemoteDefaultApp_GetEmptyVector) { std::vector permissions; - ON_CALL(*cache_manager_, IsDefaultPolicy(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsDefaultPolicy(kValidAppId)) .WillByDefault(Return(true)); ON_CALL(*access_remote_, IsAppRemoteControl(_)).WillByDefault(Return(true)); EXPECT_CALL(*access_remote_, @@ -272,12 +274,12 @@ TEST_F( GetPermissionsForApp_CannotGetFunctionalGroupsNamesForNotRemotePredataApp_GetEmptyVector) { std::vector permissions; - ON_CALL(*cache_manager_, IsPredataPolicy(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsPredataPolicy(kValidAppId)) .WillByDefault(Return(true)); - ON_CALL(*cache_manager_, + ON_CALL(*mock_cache_manager_, GetPermissionsForApp(kDeviceNumber, kPreDataConsentId, _)) .WillByDefault(Return(true)); - EXPECT_CALL(*cache_manager_, GetFunctionalGroupNames(_)) + EXPECT_CALL(*mock_cache_manager_, GetFunctionalGroupNames(_)) .WillOnce(Return(false)); policy_manager_->GetPermissionsForApp( @@ -304,9 +306,9 @@ TEST_F(PolicyManagerImplTest, LoadPT_InvalidPT_ReturnkWrongPtReceived) { std::string json = root.toStyledString(); BinaryMessage msg(json.begin(), json.end()); - EXPECT_CALL(*cache_manager_, GetVehicleDataItems()) + EXPECT_CALL(*mock_cache_manager_, GetVehicleDataItems()) .WillOnce(Return(vehicle_items)); - EXPECT_CALL(*cache_manager_, SaveUpdateRequired(false)).Times(0); + EXPECT_CALL(*mock_cache_manager_, SaveUpdateRequired(false)).Times(0); EXPECT_EQ(PolicyManager::PtProcessingResult::kWrongPtReceived, policy_manager_->LoadPT(kInValidFilename, msg)); } @@ -331,9 +333,10 @@ TEST_F(PolicyManagerImplTest, std::string json = root.toStyledString(); BinaryMessage msg(json.begin(), json.end()); - EXPECT_CALL(*cache_manager_, GetVehicleDataItems()) + EXPECT_CALL(*mock_cache_manager_, GetVehicleDataItems()) .WillOnce(Return(vehicle_items)); - EXPECT_CALL(*cache_manager_, GenerateSnapshot()).WillOnce(Return(nullptr)); + EXPECT_CALL(*mock_cache_manager_, GenerateSnapshot()) + .WillOnce(Return(nullptr)); EXPECT_EQ(PolicyManager::PtProcessingResult::kNewPtRequired, policy_manager_->LoadPT(kInValidFilename, msg)); } @@ -356,11 +359,11 @@ TEST_F(PolicyManagerImplTest, LoadPT_UpdateNotApplied_ReturnkNewPtRequired) { std::string json = root.toStyledString(); BinaryMessage msg(json.begin(), json.end()); - EXPECT_CALL(*cache_manager_, GetVehicleDataItems()) + EXPECT_CALL(*mock_cache_manager_, GetVehicleDataItems()) .WillOnce(Return(vehicle_items)); - EXPECT_CALL(*cache_manager_, GenerateSnapshot()) + EXPECT_CALL(*mock_cache_manager_, GenerateSnapshot()) .WillOnce(Return(std::make_shared(update))); - EXPECT_CALL(*cache_manager_, ApplyUpdate(_)).WillOnce(Return(false)); + EXPECT_CALL(*mock_cache_manager_, ApplyUpdate(_)).WillOnce(Return(false)); EXPECT_EQ(PolicyManager::PtProcessingResult::kNewPtRequired, policy_manager_->LoadPT(kInValidFilename, msg)); } @@ -383,11 +386,11 @@ TEST_F(PolicyManagerImplTest, LoadPT_NoHMIAppTypes_ReturnkSuccess) { std::string json = root.toStyledString(); BinaryMessage msg(json.begin(), json.end()); - ON_CALL(*cache_manager_, GetVehicleDataItems()) + ON_CALL(*mock_cache_manager_, GetVehicleDataItems()) .WillByDefault(Return(vehicle_items)); - ON_CALL(*cache_manager_, GenerateSnapshot()) + ON_CALL(*mock_cache_manager_, GenerateSnapshot()) .WillByDefault(Return(std::make_shared(update))); - ON_CALL(*cache_manager_, ApplyUpdate(_)).WillByDefault(Return(true)); + ON_CALL(*mock_cache_manager_, ApplyUpdate(_)).WillByDefault(Return(true)); EXPECT_EQ(PolicyManager::PtProcessingResult::kSuccess, policy_manager_->LoadPT(kInValidFilename, msg)); @@ -397,10 +400,10 @@ TEST_F(PolicyManagerImplTest, AddApplication_NewApplication_ReturnCallStatusChanges) { AppHmiTypes hmi_types; - ON_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillByDefault(Return(false)); - EXPECT_CALL(*cache_manager_, IsPredataPolicy(kValidAppId)).Times(0); + EXPECT_CALL(*mock_cache_manager_, IsPredataPolicy(kValidAppId)).Times(0); policy_manager_->AddApplication(kDeviceNumber, kValidAppId, hmi_types); } @@ -409,10 +412,10 @@ TEST_F(PolicyManagerImplTest, AddApplication_ExistedApplication_ReturnCallNothing) { AppHmiTypes hmi_types; - ON_CALL(*cache_manager_, IsApplicationRepresented(kValidAppId)) + ON_CALL(*mock_cache_manager_, IsApplicationRepresented(kValidAppId)) .WillByDefault(Return(true)); - EXPECT_CALL(*cache_manager_, IsPredataPolicy(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, IsPredataPolicy(kValidAppId)) .WillOnce(Return(true)); policy_manager_->AddApplication(kDeviceNumber, kValidAppId, hmi_types); @@ -422,7 +425,8 @@ TEST_F(PolicyManagerImplTest, OnPTUFinished_PtuResultIskNewPtRequired_InvokeForcePTExchange) { const std::string initial_pt_status = policy_manager_->GetPolicyTableStatus(); - EXPECT_CALL(*cache_manager_, GenerateSnapshot()).WillOnce(Return(nullptr)); + EXPECT_CALL(*mock_cache_manager_, GenerateSnapshot()) + .WillOnce(Return(nullptr)); policy_manager_->OnPTUFinished( PolicyManager::PtProcessingResult::kNewPtRequired); @@ -435,8 +439,8 @@ TEST_F( OnPTUFinished_PtuResultIskWrongPtReceived_NoPTExchangeAndNoRefreshRetrySequence) { const std::string initial_pt_status = policy_manager_->GetPolicyTableStatus(); - EXPECT_CALL(*cache_manager_, TimeoutResponse()).Times(0); - EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_)).Times(0); + EXPECT_CALL(*mock_cache_manager_, TimeoutResponse()).Times(0); + EXPECT_CALL(*mock_cache_manager_, SecondsBetweenRetries(_)).Times(0); policy_manager_->OnPTUFinished( PolicyManager::PtProcessingResult::kWrongPtReceived); @@ -448,8 +452,8 @@ TEST_F(PolicyManagerImplTest, OnPTUFinished_PtuResultIskSuccess_InvokeRefreshRetrySequence) { const std::string initial_pt_status = policy_manager_->GetPolicyTableStatus(); - EXPECT_CALL(*cache_manager_, TimeoutResponse()); - EXPECT_CALL(*cache_manager_, SecondsBetweenRetries(_)); + EXPECT_CALL(*mock_cache_manager_, TimeoutResponse()); + EXPECT_CALL(*mock_cache_manager_, SecondsBetweenRetries(_)); policy_manager_->OnPTUFinished(PolicyManager::PtProcessingResult::kSuccess); const std::string final_pt_status = policy_manager_->GetPolicyTableStatus(); @@ -457,7 +461,8 @@ TEST_F(PolicyManagerImplTest, } TEST_F(PolicyManagerImplTest, RequestPTUpdate_SnapshotPtrIsNull_ReturnFalse) { - ON_CALL(*cache_manager_, GenerateSnapshot()).WillByDefault(Return(nullptr)); + ON_CALL(*mock_cache_manager_, GenerateSnapshot()) + .WillByDefault(Return(nullptr)); EXPECT_FALSE( policy_manager_->RequestPTUpdate(PTUIterationType::DefaultIteration)); @@ -486,7 +491,8 @@ TEST_F(PolicyManagerImplTest, RequestPTUpdate_PTIsValid_PTIsUpdated) { snapshot->SetPolicyTableType(policy_table::PT_SNAPSHOT); ASSERT_TRUE(IsValid(*snapshot)); - ON_CALL(*cache_manager_, GenerateSnapshot()).WillByDefault(Return(snapshot)); + ON_CALL(*mock_cache_manager_, GenerateSnapshot()) + .WillByDefault(Return(snapshot)); EXPECT_CALL(listener_, OnSnapshotCreated(_, PTUIterationType::DefaultIteration)); EXPECT_TRUE( @@ -519,9 +525,10 @@ TEST_F(PolicyManagerImplTest, GetUserConsentForApp_NoPermissionsForApp_NoConsent) { std::vector permissions; - ON_CALL(*cache_manager_, GetPermissionsForApp(kDeviceNumber, kValidAppId, _)) + ON_CALL(*mock_cache_manager_, + GetPermissionsForApp(kDeviceNumber, kValidAppId, _)) .WillByDefault(Return(false)); - EXPECT_CALL(*cache_manager_, GetFunctionalGroupNames(_)).Times(0); + EXPECT_CALL(*mock_cache_manager_, GetFunctionalGroupNames(_)).Times(0); policy_manager_->GetUserConsentForApp( kDeviceNumber, kValidAppId, permissions); @@ -532,9 +539,10 @@ TEST_F(PolicyManagerImplTest, GetUserConsentForApp_NoFunctionalGroupsNames_NoConsent) { std::vector permissions; - ON_CALL(*cache_manager_, GetPermissionsForApp(kDeviceNumber, kValidAppId, _)) + ON_CALL(*mock_cache_manager_, + GetPermissionsForApp(kDeviceNumber, kValidAppId, _)) .WillByDefault(Return(true)); - EXPECT_CALL(*cache_manager_, GetFunctionalGroupNames(_)) + EXPECT_CALL(*mock_cache_manager_, GetFunctionalGroupNames(_)) .WillOnce(Return(false)); policy_manager_->GetUserConsentForApp( @@ -552,7 +560,7 @@ TEST_F(PolicyManagerImplTest, GetInitialAppData_HandleValidPointers_ReturnTrue) { StringArray nicknames; StringArray app_hmi_types; - ON_CALL(*cache_manager_, + ON_CALL(*mock_cache_manager_, GetInitialAppData(kValidAppId, nicknames, app_hmi_types)) .WillByDefault(Return(true)); @@ -562,15 +570,15 @@ TEST_F(PolicyManagerImplTest, TEST_F(PolicyManagerImplTest, GetAppPermissionsChanges_NoPermissionsChanges_GeneratePermissions) { - EXPECT_CALL(*cache_manager_, IsApplicationRevoked(kValidAppId)); - EXPECT_CALL(*cache_manager_, GetPriority(kValidAppId, _)); + EXPECT_CALL(*mock_cache_manager_, IsApplicationRevoked(kValidAppId)); + EXPECT_CALL(*mock_cache_manager_, GetPriority(kValidAppId, _)); policy_manager_->GetAppPermissionsChanges(kDeviceNumber, kValidAppId); } TEST_F(PolicyManagerImplTest, GetHMITypes_AppIsDefaultPolicy_ReturnFalse) { std::vector app_types; - EXPECT_CALL(*cache_manager_, IsDefaultPolicy(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, IsDefaultPolicy(kValidAppId)) .WillOnce(Return(true)); EXPECT_FALSE(policy_manager_->GetHMITypes(kValidAppId, &app_types)); @@ -578,7 +586,7 @@ TEST_F(PolicyManagerImplTest, GetHMITypes_AppIsDefaultPolicy_ReturnFalse) { TEST_F(PolicyManagerImplTest, GetHMITypes_NoHmiTypes_ReturnFalse) { std::vector app_types; - EXPECT_CALL(*cache_manager_, GetHMITypes(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, GetHMITypes(kValidAppId)) .WillOnce(Return(nullptr)); EXPECT_FALSE(policy_manager_->GetHMITypes(kValidAppId, &app_types)); } @@ -586,11 +594,25 @@ TEST_F(PolicyManagerImplTest, GetHMITypes_NoHmiTypes_ReturnFalse) { TEST_F(PolicyManagerImplTest, GetHMITypes_ValidHmiTypes_ReturnTrue) { std::vector app_types; AppHMITypes hmi_types; - EXPECT_CALL(*cache_manager_, GetHMITypes(kValidAppId)) + EXPECT_CALL(*mock_cache_manager_, GetHMITypes(kValidAppId)) .WillOnce(Return(&hmi_types)); EXPECT_TRUE(policy_manager_->GetHMITypes(kValidAppId, &app_types)); } +TEST_F(PolicyManagerImplTest, SetMetaInfo_SetCCPUVersion_SUCCESS) { + const std::string ccpu_version = "ccpu_version"; + const std::string wers_country_code = "wersCountryCode"; + const std::string language = "language"; + + EXPECT_CALL(*mock_cache_manager_, + SetMetaInfo(ccpu_version, wers_country_code, language)); + policy_manager_->SetSystemInfo(ccpu_version, wers_country_code, language); + + EXPECT_CALL(*mock_cache_manager_, GetCCPUVersionFromPT()) + .WillOnce(Return(ccpu_version)); + EXPECT_EQ(ccpu_version, policy_manager_->GetCCPUVersionFromPT()); +} + } // namespace policy_test } // namespace components } // namespace test -- cgit v1.2.1 From f2119f4b997b7ef8d3d8f771412e1e743c221713 Mon Sep 17 00:00:00 2001 From: Collin Date: Thu, 23 Jul 2020 14:09:33 -0400 Subject: allow button events to be forwarded to apps in LIMITED (#3461) * allow button events to be forwarded to subscribed mobile apps in hmi level LIMITED for all buttons besides OK * fixup! allow button events to be forwarded to subscribed mobile apps in hmi level LIMITED for all buttons besides OK use existing var and clean up condition * fix description of OnButtonPress and OnButtonEvent param appID --- .../src/commands/mobile/on_button_event_notification.cc | 6 ++++-- .../src/commands/mobile/on_button_press_notification.cc | 6 ++++-- src/components/interfaces/HMI_API.xml | 6 ++---- 3 files changed, 10 insertions(+), 8 deletions(-) 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 bca3b20fe0..9c4be847a1 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 @@ -139,8 +139,10 @@ void OnButtonEventNotification::Run() { << "in FULL or LIMITED hmi level"); continue; } - // if "app_id" absent send notification only in HMI_FULL mode - if (is_app_id_exists || subscribed_app->IsFullscreen()) { + // 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); } } 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 a205660e23..87d16e87e6 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 @@ -149,8 +149,10 @@ void OnButtonPressNotification::Run() { if (app->app_id() == subscribed_app->app_id()) { SendButtonPress(subscribed_app); } - } else if (subscribed_app->IsFullscreen()) { - // if No "appID" - send it FULL apps only. + } 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); } } diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 0b189c4bca..b40076e9d0 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -4204,10 +4204,9 @@ - In case the ButtonName is CUSTOM_BUTTON or OK, HMI must include appID parameters to OnButtonPress notification sent to SDL. If appID is not sent together with CUSTOM_BUTTON, this notification will be ignored by SDL. If appID is present for OK button -> SDL transfers notification to the named app only if it is in FULL or LIMITED (ignores if app is in NONE or BACKGROUND). - If appID is omited for OK button -> SDL transfers notification to app in FULL + If appID is omitted for OK button -> SDL transfers notification to app in FULL @@ -4221,10 +4220,9 @@ - In case the ButtonName is CUSTOM_BUTTON or OK, HMI must include appID parameters to OnButtonEvent notification sent to SDL. If appID is not sent together with CUSTOM_BUTTON, this notification will be ignored by SDL. If appID is present for OK button -> SDL transfers notification to the named app only if it is in FULL or LIMITED (ignores if app is in NONE or BACKGROUND). - If appID is omited for OK button -> SDL transfers notification to app in FULL + If appID is omitted for OK button -> SDL transfers notification to app in FULL -- cgit v1.2.1