diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2018-06-18 12:01:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-18 12:01:38 -0700 |
commit | 9c6a43aad481a1b45a50ccc40b456bb168989f47 (patch) | |
tree | cf21b340a414c183d92c733091e159390186022b /src/components/application_manager/src | |
parent | 28c8a64c67b137508bfc1b9ec35b6723fae992db (diff) | |
parent | 24edd97c1f2b4fc67eb882245cd865939b075c6f (diff) | |
download | sdl_core-9c6a43aad481a1b45a50ccc40b456bb168989f47.tar.gz |
Merge branch 'develop' into feat/mt_transport_changes
Diffstat (limited to 'src/components/application_manager/src')
32 files changed, 1601 insertions, 396 deletions
diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index a81540708c..226c83dbf6 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -173,6 +173,9 @@ DynamicApplicationDataImpl::DynamicApplicationDataImpl() , menu_title_(NULL) , menu_icon_(NULL) , tbt_show_command_(NULL) + , day_color_scheme_(NULL) + , night_color_scheme_(NULL) + , display_layout_("") , commands_() , commands_lock_(true) , sub_menu_() @@ -214,6 +217,16 @@ DynamicApplicationDataImpl::~DynamicApplicationDataImpl() { tbt_show_command_ = NULL; } + if (day_color_scheme_) { + delete day_color_scheme_; + day_color_scheme_ = NULL; + } + + if (night_color_scheme_) { + delete night_color_scheme_; + night_color_scheme_ = NULL; + } + for (CommandsMap::iterator command_it = commands_.begin(); commands_.end() != command_it; ++command_it) { @@ -290,6 +303,20 @@ const smart_objects::SmartObject* DynamicApplicationDataImpl::menu_icon() return menu_icon_; } +const smart_objects::SmartObject* DynamicApplicationDataImpl::day_color_scheme() + const { + return day_color_scheme_; +} + +const smart_objects::SmartObject* +DynamicApplicationDataImpl::night_color_scheme() const { + return night_color_scheme_; +} + +const std::string& DynamicApplicationDataImpl::display_layout() const { + return display_layout_; +} + void DynamicApplicationDataImpl::load_global_properties( const smart_objects::SmartObject& properties_so) { SetGlobalProperties(properties_so.getElement(strings::vr_help_title), @@ -405,6 +432,28 @@ void DynamicApplicationDataImpl::set_menu_icon( menu_icon_ = new smart_objects::SmartObject(menu_icon); } +void DynamicApplicationDataImpl::set_day_color_scheme( + const smart_objects::SmartObject& color_scheme) { + if (day_color_scheme_) { + delete day_color_scheme_; + } + + day_color_scheme_ = new smart_objects::SmartObject(color_scheme); +} + +void DynamicApplicationDataImpl::set_night_color_scheme( + const smart_objects::SmartObject& color_scheme) { + if (night_color_scheme_) { + delete night_color_scheme_; + } + + night_color_scheme_ = new smart_objects::SmartObject(color_scheme); +} + +void DynamicApplicationDataImpl::set_display_layout(const std::string& layout) { + display_layout_ = layout; +} + void DynamicApplicationDataImpl::SetGlobalProperties( const smart_objects::SmartObject& param, void (DynamicApplicationData::*callback)( diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 6736051d15..ff8edc9f55 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -232,7 +232,26 @@ void ApplicationImpl::set_voice_communication_supported( } bool ApplicationImpl::IsAudioApplication() const { - return is_media_ || is_voice_communication_application_ || is_navi_; + const bool is_audio_app = + is_media_application() || is_voice_communication_supported() || is_navi(); + LOG4CXX_DEBUG(logger_, + std::boolalpha << "is audio app --> ((is_media_app: " + << is_media_application() << ")" + << " || (is_voice_communication_app: " + << is_voice_communication_supported() << ")" + << " || (is_navi: " << is_navi() << ")) --> " + << is_audio_app); + return is_audio_app; +} + +bool ApplicationImpl::IsVideoApplication() const { + const bool is_video_app = is_navi() || mobile_projection_enabled(); + LOG4CXX_DEBUG(logger_, + std::boolalpha + << "is video app --> ((is_navi: " << is_navi() << ")" + << " || (mobile_projection: " << mobile_projection_enabled() + << ")) --> " << is_video_app); + return is_video_app; } void ApplicationImpl::SetRegularState(HmiStatePtr state) { diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 01c874c0e5..7eed91ba86 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -557,6 +557,7 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( CreateRegularState(utils::SharedPtr<Application>(application), mobile_apis::HMILevel::INVALID_ENUM, mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_apis::VideoStreamingState::INVALID_ENUM, mobile_api::SystemContext::SYSCTXT_MAIN); application->SetInitialState(initial_state); @@ -631,6 +632,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( const std::string& bundle_id = app_info[strings::bundle_id].asString(); application->set_bundle_id(bundle_id); } + + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); + if (file_system::FileExists(full_icon_path)) { + application->set_app_icon_path(full_icon_path); + } + PutDriverDistractionMessageToPostponed(application); // Stops timer of saving data to resumption in order to @@ -677,13 +685,18 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN(app, false); + LOG4CXX_DEBUG(logger_, "Activating application with id:" << app->app_id()); + // remove from resumption if app was activated by user resume_controller().OnAppActivated(app); - HMILevel::eType hmi_level = HMILevel::HMI_FULL; - AudioStreamingState::eType audio_state; - app->IsAudioApplication() ? audio_state = AudioStreamingState::AUDIBLE - : audio_state = AudioStreamingState::NOT_AUDIBLE; - state_ctrl_.SetRegularState(app, hmi_level, audio_state, false); + const HMILevel::eType hmi_level = HMILevel::HMI_FULL; + const AudioStreamingState::eType audio_state = + app->IsAudioApplication() ? AudioStreamingState::AUDIBLE + : AudioStreamingState::NOT_AUDIBLE; + const VideoStreamingState::eType video_state = + app->IsVideoApplication() ? VideoStreamingState::STREAMABLE + : VideoStreamingState::NOT_STREAMABLE; + state_ctrl_.SetRegularState(app, hmi_level, audio_state, video_state, false); return true; } @@ -695,10 +708,10 @@ mobile_api::HMILevel::eType ApplicationManagerImpl::IsHmiLevelFullAllowed( NOTREACHED(); return mobile_api::HMILevel::INVALID_ENUM; } - bool is_audio_app = app->IsAudioApplication(); - bool does_audio_app_with_same_type_exist = + const bool is_audio_app = app->IsAudioApplication(); + const bool does_audio_app_with_same_type_exist = IsAppTypeExistsInFullOrLimited(app); - bool is_active_app_exist = active_application().valid(); + const bool is_active_app_exist = active_application().valid(); mobile_api::HMILevel::eType result = mobile_api::HMILevel::HMI_FULL; if (is_audio_app && does_audio_app_with_same_type_exist) { @@ -860,10 +873,12 @@ HmiStatePtr ApplicationManagerImpl::CreateRegularState( utils::SharedPtr<Application> app, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::VideoStreamingState::eType video_state, mobile_apis::SystemContext::eType system_context) const { HmiStatePtr state(new HmiState(app, *this)); state->set_hmi_level(hmi_level); state->set_audio_streaming_state(audio_state); + state->set_video_streaming_state(video_state); state->set_system_context(system_context); return state; } @@ -880,12 +895,6 @@ HmiStatePtr ApplicationManagerImpl::CreateRegularState( return state; } -bool ApplicationManagerImpl::IsStateActive(HmiState::StateID state_id) const { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "Checking for active state id " << state_id); - return state_ctrl_.IsStateActive(state_id); -} - void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key, int32_t correlation_id, int32_t max_duration, @@ -1858,6 +1867,11 @@ bool ApplicationManagerImpl::OnHandshakeDone( return false; } +bool ApplicationManagerImpl::OnHandshakeFailed() { + LOG4CXX_AUTO_TRACE(logger_); + return false; +} + void ApplicationManagerImpl::OnCertificateUpdateRequired() { LOG4CXX_AUTO_TRACE(logger_); GetPolicyHandler().OnPTExchangeNeeded(); @@ -3728,7 +3742,6 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { void ApplicationManagerImpl::OnAppStreaming( uint32_t app_id, protocol_handler::ServiceType service_type, bool state) { - using namespace protocol_handler; LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application(app_id); @@ -3741,11 +3754,11 @@ void ApplicationManagerImpl::OnAppStreaming( DCHECK_OR_RETURN_VOID(media_manager_); if (state) { - state_ctrl_.OnNaviStreamingStarted(); + state_ctrl_.OnVideoStreamingStarted(app); media_manager_->StartStreaming(app_id, service_type); } else { media_manager_->StopStreaming(app_id, service_type); - state_ctrl_.OnNaviStreamingStopped(); + state_ctrl_.OnVideoStreamingStarted(app); } } @@ -3906,6 +3919,9 @@ void ApplicationManagerImpl::SendHMIStatusNotification( message[strings::msg_params][strings::audio_streaming_state] = static_cast<int32_t>(app->audio_streaming_state()); + message[strings::msg_params][strings::video_streaming_state] = + static_cast<int32_t>(app->video_streaming_state()); + message[strings::msg_params][strings::system_context] = static_cast<int32_t>(app->system_context()); @@ -4228,6 +4244,8 @@ mobile_apis::AppHMIType::eType ApplicationManagerImpl::StringToAppHMIType( return mobile_apis::AppHMIType::MESSAGING; } else if ("NAVIGATION" == str) { return mobile_apis::AppHMIType::NAVIGATION; + } else if ("PROJECTION" == str) { + return mobile_apis::AppHMIType::PROJECTION; } else if ("INFORMATION" == str) { return mobile_apis::AppHMIType::INFORMATION; } else if ("SOCIAL" == str) { @@ -4667,6 +4685,23 @@ std::vector<std::string> ApplicationManagerImpl::ConvertRejectedParamList( return output; } +bool ApplicationManagerImpl::IsSOStructValid( + const hmi_apis::StructIdentifiers::eType struct_id, + const smart_objects::SmartObject& display_capabilities) { + smart_objects::SmartObject display_capabilities_so = display_capabilities; + if (hmi_so_factory().AttachSchema(struct_id, display_capabilities_so)) { + if (display_capabilities_so.isValid()) { + return true; + } else { + return false; + } + } else { + LOG4CXX_ERROR(logger_, "Could not find struct id: " << struct_id); + return false; + } + return true; +} + #ifdef BUILD_TESTS void ApplicationManagerImpl::AddMockApplication(ApplicationSharedPtr mock_app) { applications_list_lock_.Acquire(); @@ -4734,7 +4769,6 @@ std::vector<std::string> ApplicationManagerImpl::devices( void ApplicationManagerImpl::ChangeAppsHMILevel( uint32_t app_id, mobile_apis::HMILevel::eType level) { - using namespace mobile_apis::HMILevel; LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "AppID to change: " << app_id << " -> " << level); ApplicationSharedPtr app = application(app_id); @@ -4742,14 +4776,13 @@ void ApplicationManagerImpl::ChangeAppsHMILevel( LOG4CXX_ERROR(logger_, "There is no app with id: " << app_id); return; } - eType old_level = app->hmi_level(); + const mobile_apis::HMILevel::eType old_level = app->hmi_level(); if (old_level != level) { app->set_hmi_level(level); OnHMILevelChanged(app_id, old_level, level); - plugin_manager_.OnAppHMILevelChanged(app, old_level); } else { - LOG4CXX_WARN(logger_, "Redudant changing HMI level : " << level); + LOG4CXX_WARN(logger_, "Redundant changing HMI level: " << level); } } diff --git a/src/components/application_manager/src/application_state.cc b/src/components/application_manager/src/application_state.cc index 101a565a8e..3f775ee4e2 100644 --- a/src/components/application_manager/src/application_state.cc +++ b/src/components/application_manager/src/application_state.cc @@ -101,7 +101,6 @@ void ApplicationState::RemoveState(HmiState::StateID state) { } HmiStatePtr ApplicationState::GetState(HmiState::StateID state_id) const { - LOG4CXX_AUTO_TRACE(logger_); switch (state_id) { case HmiState::StateID::STATE_ID_REGULAR: LOG4CXX_DEBUG(logger_, "Getting regular state."); 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 515d8a998c..527d640c5c 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -39,6 +39,7 @@ #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" #include "smart_objects/smart_object.h" + namespace application_manager { namespace commands { @@ -605,10 +606,8 @@ bool CommandRequestImpl::CheckAllowedParameters() { smart_objects::SmartMap::const_iterator iter_end = s_map.map_end(); for (; iter != iter_end; ++iter) { - if (iter->second.asBool()) { - LOG4CXX_DEBUG(logger_, "Request's param: " << iter->first); - params.insert(iter->first); - } + LOG4CXX_DEBUG(logger_, "Request's param: " << iter->first); + params.insert(iter->first); } mobile_apis::Result::eType check_result = diff --git a/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_request.cc b/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_request.cc new file mode 100644 index 0000000000..215b0404a7 --- /dev/null +++ b/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_request.cc @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, 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 + * distribut wiion. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/commands/hmi/basic_communication_get_system_time_request.h" + +namespace application_manager { + +namespace commands { + +BasicCommunicationGetSystemTimeRequest::BasicCommunicationGetSystemTimeRequest( + const MessageSharedPtr& message, ApplicationManager& application_manager) + : RequestToHMI(message, application_manager) {} + +void BasicCommunicationGetSystemTimeRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + application_manager_.protocol_handler().NotifyOnFailedHandshake(); +} + +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_response.cc b/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_response.cc new file mode 100644 index 0000000000..26dd115d1a --- /dev/null +++ b/src/components/application_manager/src/commands/hmi/basic_communication_get_system_time_response.cc @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/commands/hmi/basic_communication_get_system_time_response.h" +#include "utils/logger.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "Commands") + +namespace application_manager { +namespace commands { + +BasicCommunicationGetSystemTimeResponse:: + BasicCommunicationGetSystemTimeResponse( + const MessageSharedPtr& message, + ApplicationManager& application_manager) + : ResponseFromHMI(message, application_manager) {} + +void BasicCommunicationGetSystemTimeResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + event_engine::Event event( + hmi_apis::FunctionID::BasicCommunication_GetSystemTime); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc b/src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc index efdfaf8f3e..df9dc01eab 100644 --- a/src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc @@ -105,7 +105,11 @@ void OnExitApplicationNotification::Run() { } application_manager_.state_controller().SetRegularState( - app_impl, HMILevel::HMI_NONE, AudioStreamingState::NOT_AUDIBLE, false); + app_impl, + HMILevel::HMI_NONE, + AudioStreamingState::NOT_AUDIBLE, + VideoStreamingState::NOT_STREAMABLE, + false); } } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/on_system_time_ready_notification.cc b/src/components/application_manager/src/commands/hmi/on_system_time_ready_notification.cc new file mode 100644 index 0000000000..d2376e6dfe --- /dev/null +++ b/src/components/application_manager/src/commands/hmi/on_system_time_ready_notification.cc @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/commands/hmi/on_system_time_ready_notification.h" + +#include "application_manager/event_engine/event.h" +#include "interfaces/HMI_API.h" + +namespace application_manager { + +namespace commands { + +OnSystemTimeReadyNotification::OnSystemTimeReadyNotification( + const MessageSharedPtr& message, ApplicationManager& application_manager) + : NotificationFromHMI(message, application_manager) {} + +OnSystemTimeReadyNotification::~OnSystemTimeReadyNotification() {} + +void OnSystemTimeReadyNotification::Run() { + event_engine::Event event( + hmi_apis::FunctionID::BasicCommunication_OnSystemTimeReady); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); +} + +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc index 6905e7cdef..23c020bca2 100644 --- a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc @@ -74,7 +74,9 @@ bool RequestToHMI::CleanUp() { return true; } -void RequestToHMI::Run() {} +void RequestToHMI::Run() { + SendRequest(); +} void RequestToHMI::SendRequest() { (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; diff --git a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc index d5767690d7..dee364cb99 100644 --- a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc @@ -92,6 +92,21 @@ void AlertManeuverRequest::Run() { // check TTSChunk parameter if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) { + smart_objects::SmartObject& tts_chunks = + (*message_)[strings::msg_params][strings::tts_chunks]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + SendResponse(false, + mobile_apis::Result::FILE_NOT_FOUND, + "One or more files needed for tts_chunks are not present"); + return; + } + if (0 < (*message_)[strings::msg_params][strings::tts_chunks].length()) { pending_requests_.Add(hmi_apis::FunctionID::TTS_Speak); tts_is_ok = true; diff --git a/src/components/application_manager/src/commands/mobile/alert_request.cc b/src/components/application_manager/src/commands/mobile/alert_request.cc index 3c42e43767..e0cbe9e600 100644 --- a/src/components/application_manager/src/commands/mobile/alert_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_request.cc @@ -281,6 +281,23 @@ bool AlertRequest::Validate(uint32_t app_id) { return false; } + if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) { + smart_objects::SmartObject& tts_chunks = + (*message_)[strings::msg_params][strings::tts_chunks]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + SendResponse(false, + mobile_apis::Result::FILE_NOT_FOUND, + "One or more files needed for tts_chunks are not present"); + return false; + } + } + return true; } diff --git a/src/components/application_manager/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/src/commands/mobile/change_registration_request.cc index f55767c723..06027a42db 100644 --- a/src/components/application_manager/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/src/commands/mobile/change_registration_request.cc @@ -178,6 +178,23 @@ void ChangeRegistrationRequest::Run() { return; } + if ((*message_)[strings::msg_params].keyExists(strings::tts_name)) { + smart_objects::SmartObject& tts_name = + (*message_)[strings::msg_params][strings::tts_name]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(tts_name, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + SendResponse(false, + mobile_apis::Result::FILE_NOT_FOUND, + "One or more files needed for tts_name are not present"); + return; + } + } + const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); const HmiInterfaces::InterfaceState vr_state = diff --git a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc index c29ff3e2d3..f06012893e 100644 --- a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc @@ -36,6 +36,7 @@ #include "application_manager/commands/mobile/on_system_request_notification.h" #include "interfaces/MOBILE_API.h" #include "utils/file_system.h" +#include "policy/policy_table/enums.h" #include "application_manager/application_manager.h" #include "application_manager/policies/policy_handler_interface.h" @@ -65,19 +66,40 @@ void OnSystemRequestNotification::Run() { return; } - RequestType::eType request_type = static_cast<RequestType::eType>( - (*message_)[strings::msg_params][strings::request_type].asInt()); + const mobile_apis::RequestType::eType request_type = + static_cast<mobile_apis::RequestType::eType>( + (*message_)[strings::msg_params][strings::request_type].asInt()); const policy::PolicyHandlerInterface& policy_handler = application_manager_.GetPolicyHandler(); + + const std::string stringified_request_type = + rpc::policy_table_interface_base::EnumToJsonString( + static_cast<rpc::policy_table_interface_base::RequestType>( + request_type)); + if (!policy_handler.IsRequestTypeAllowed(app->policy_app_id(), request_type)) { LOG4CXX_WARN(logger_, - "Request type " << request_type + "Request type " << stringified_request_type << " is not allowed by policies"); return; } - if (RequestType::PROPRIETARY == request_type) { + const bool request_subtype_present = + (*message_)[strings::msg_params].keyExists(strings::request_subtype); + if (request_subtype_present) { + const std::string request_subtype = + (*message_)[strings::msg_params][strings::request_subtype].asString(); + if (!policy_handler.IsRequestSubTypeAllowed(app->policy_app_id(), + request_subtype)) { + LOG4CXX_ERROR(logger_, + "Request subtype: " << request_subtype + << " is DISALLOWED by policies"); + return; + } + } + + if (mobile_apis::RequestType::PROPRIETARY == request_type) { /* According to requirements: "If the requestType = PROPRIETARY, add to mobile API fileType = JSON If the requestType = HTTP, add to mobile API fileType = BINARY" @@ -97,7 +119,7 @@ void OnSystemRequestNotification::Run() { #endif // PROPRIETARY_MODE (*message_)[strings::msg_params][strings::file_type] = FileType::JSON; - } else if (RequestType::HTTP == request_type) { + } else if (mobile_apis::RequestType::HTTP == request_type) { (*message_)[strings::msg_params][strings::file_type] = FileType::BINARY; if ((*message_)[strings::msg_params].keyExists(strings::url)) { (*message_)[strings::msg_params][strings::timeout] = @@ -183,8 +205,8 @@ size_t OnSystemRequestNotification::ParsePTString( if (pt_string[i] == '\"' || pt_string[i] == '\\') { result += '\\'; } else if (pt_string[i] == '\n') { - result_length--; // contentLength is adjusted when this character is not - // copied to result. + result_length--; // contentLength is adjusted when this character is + // not copied to result. continue; } result += pt_string[i]; diff --git a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc index 20076ac50c..a758f04aac 100644 --- a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -96,8 +96,24 @@ void PerformAudioPassThruRequest::Run() { // need set flag before sending to hmi StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); - if ((*message_)[str::msg_params].keyExists(str::initial_prompt) && - (0 < (*message_)[str::msg_params][str::initial_prompt].length())) { + if ((*message_)[str::msg_params].keyExists(str::initial_prompt)) { + smart_objects::SmartObject& initial_prompt = + (*message_)[strings::msg_params][strings::initial_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles( + initial_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + SendResponse( + false, + mobile_apis::Result::FILE_NOT_FOUND, + "One or more files needed for initial_prompt are not present"); + return; + } + // In case TTS Speak, subscribe on notification SendSpeakRequest(); SendPerformAudioPassThruRequest(); diff --git a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc index 68940158b9..86ab0a97c0 100644 --- a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include <numeric> #include <string.h> #include <string> #include "application_manager/commands/mobile/perform_interaction_request.h" @@ -536,9 +537,21 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( } } + std::vector<std::string> invalid_params; if ((*message_)[strings::msg_params].keyExists(strings::help_prompt)) { - msg_params[strings::help_prompt] = + smart_objects::SmartObject& help_prompt = (*message_)[strings::msg_params][strings::help_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(help_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_WARN(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + invalid_params.push_back("help_prompt"); + } else { + msg_params[strings::help_prompt] = help_prompt; + } } else { if (choice_list.length() != 0) { msg_params[strings::help_prompt] = @@ -573,8 +586,20 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( } if ((*message_)[strings::msg_params].keyExists(strings::timeout_prompt)) { - msg_params[strings::timeout_prompt] = + smart_objects::SmartObject& timeout_prompt = (*message_)[strings::msg_params][strings::timeout_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles( + timeout_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_WARN(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + invalid_params.push_back("timeout_prompt"); + } else { + msg_params[strings::timeout_prompt] = timeout_prompt; + } } else { if (msg_params.keyExists(strings::help_prompt)) { msg_params[strings::timeout_prompt] = msg_params[strings::help_prompt]; @@ -582,8 +607,34 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( } if ((*message_)[strings::msg_params].keyExists(strings::initial_prompt)) { - msg_params[strings::initial_prompt] = + smart_objects::SmartObject& initial_prompt = (*message_)[strings::msg_params][strings::initial_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles( + initial_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_WARN(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + invalid_params.push_back("initial_prompt"); + } else { + msg_params[strings::initial_prompt] = initial_prompt; + } + } + + if (!invalid_params.empty()) { + const std::string params_list = + std::accumulate(std::begin(invalid_params), + std::end(invalid_params), + std::string(""), + [](std::string& first, std::string& second) { + return first.empty() ? second : first + ", " + second; + }); + const std::string info = + "One or more files needed for " + params_list + " are not present"; + SendResponse(false, mobile_apis::Result::FILE_NOT_FOUND, info.c_str()); + return; } mobile_apis::InteractionMode::eType mode = diff --git a/src/components/application_manager/src/commands/mobile/put_file_request.cc b/src/components/application_manager/src/commands/mobile/put_file_request.cc index 602b420ba0..269c9c814e 100644 --- a/src/components/application_manager/src/commands/mobile/put_file_request.cc +++ b/src/components/application_manager/src/commands/mobile/put_file_request.cc @@ -38,6 +38,22 @@ #include "application_manager/application_impl.h" #include "utils/file_system.h" +#include <boost/crc.hpp> + +namespace { +/** +* Calculates CRC32 checksum +* @param binary_data - input data for which CRC32 should be calculated +* @return calculated CRC32 checksum +*/ +uint32_t GetCrc32CheckSum(const std::vector<uint8_t>& binary_data) { + const std::size_t file_size = binary_data.size(); + boost::crc_32_type result; + result.process_bytes(&binary_data[0], file_size); + return result.checksum(); +} + +} // namespace namespace application_manager { @@ -137,7 +153,7 @@ void PutFileRequest::Run() { is_persistent_file_ = false; bool is_system_file = false; length_ = binary_data.size(); - bool is_download_compleate = true; + bool is_download_complete = true; bool offset_exist = (*message_)[strings::msg_params].keyExists(strings::offset); @@ -187,11 +203,29 @@ void PutFileRequest::Run() { return; } const std::string full_path = file_path + "/" + sync_file_name_; - UNUSED(full_path); + const size_t bin_data_size = binary_data.size(); + + if ((*message_)[strings::msg_params].keyExists(strings::crc32_check_sum)) { + LOG4CXX_TRACE(logger_, "Binary Data Size: " << bin_data_size); + const uint32_t crc_received = + (*message_)[strings::msg_params][strings::crc32_check_sum].asUInt(); + LOG4CXX_TRACE(logger_, "CRC32 SUM Received: " << crc_received); + const uint32_t crc_calculated = GetCrc32CheckSum(binary_data); + LOG4CXX_TRACE(logger_, "CRC32 SUM Calculated: " << crc_calculated); + if (crc_calculated != crc_received) { + SendResponse(false, + mobile_apis::Result::CORRUPTED_DATA, + "CRC Check on file failed. File upload has been cancelled, " + "please retry.", + &response_params); + return; + } + } + LOG4CXX_DEBUG(logger_, - "Wrtiting " << binary_data.size() << "bytes to " << full_path - << " (current size is" - << file_system::FileSize(full_path) << ")"); + "Writing " << bin_data_size << " bytes to " << full_path + << " (current size is" + << file_system::FileSize(full_path) << ")"); mobile_apis::Result::eType save_result = application_manager_.SaveBinary( binary_data, file_path, sync_file_name_, offset_); @@ -211,7 +245,7 @@ void PutFileRequest::Run() { if (!is_system_file) { AppFile file(sync_file_name_, is_persistent_file_, - is_download_compleate, + is_download_complete, file_type_); if (0 == offset_) { diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index adf5925e02..15f4f75758 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -50,6 +50,7 @@ #include "config_profile/profile.h" #include "interfaces/MOBILE_API.h" #include "interfaces/generated_msg_version.h" +#include "utils/file_system.h" namespace { namespace custom_str = utils::custom_string; @@ -178,7 +179,7 @@ namespace commands { RegisterAppInterfaceRequest::RegisterAppInterfaceRequest( const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandRequestImpl(message, application_manager) - , result_checking_app_hmi_type_(mobile_apis::Result::INVALID_ENUM) {} + , result_code_(mobile_apis::Result::INVALID_ENUM) {} RegisterAppInterfaceRequest::~RegisterAppInterfaceRequest() {} @@ -319,7 +320,20 @@ void RegisterAppInterfaceRequest::Run() { } if (msg_params.keyExists(strings::tts_name)) { - application->set_tts_name(msg_params[strings::tts_name]); + smart_objects::SmartObject& tts_name = + (*message_)[strings::msg_params][strings::tts_name]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles( + tts_name, application, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_WARN(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + response_info_ = "One or more files needed for tts_name are not present"; + result_code_ = mobile_apis::Result::WARNINGS; + } + application->set_tts_name(tts_name); } if (msg_params.keyExists(strings::app_hmi_type)) { @@ -348,6 +362,15 @@ void RegisterAppInterfaceRequest::Run() { } } + if (msg_params.keyExists(strings::day_color_scheme)) { + application->set_day_color_scheme(msg_params[strings::day_color_scheme]); + } + + if (msg_params.keyExists(strings::night_color_scheme)) { + application->set_night_color_scheme( + msg_params[strings::night_color_scheme]); + } + // Add device to policy table and set device info, if any policy::DeviceParams dev_params; if (-1 == @@ -440,50 +463,69 @@ void FillUIRelatedFields(smart_objects::SmartObject& response_params, smart_objects::SmartObject& display_caps = response_params[hmi_response::display_capabilities]; - display_caps[hmi_response::display_type] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::display_type); - - display_caps[hmi_response::text_fields] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::text_fields); - - display_caps[hmi_response::image_fields] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::image_fields); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::display_type)) { + display_caps[hmi_response::display_type] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::display_type); + } - display_caps[hmi_response::media_clock_formats] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::media_clock_formats); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::display_name)) { + display_caps[hmi_response::display_name] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::display_name); + } - display_caps[hmi_response::templates_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::templates_available); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::text_fields)) { + display_caps[hmi_response::text_fields] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::text_fields); + } - display_caps[hmi_response::screen_params] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::screen_params); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::image_fields)) { + display_caps[hmi_response::image_fields] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::image_fields); + } - display_caps[hmi_response::num_custom_presets_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::num_custom_presets_available); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::media_clock_formats)) { + display_caps[hmi_response::media_clock_formats] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::media_clock_formats); + } - display_caps[hmi_response::graphic_supported] = - (hmi_capabilities.display_capabilities() - ->getElement(hmi_response::image_capabilities) - .length() > 0); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::templates_available)) { + display_caps[hmi_response::templates_available] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::templates_available); + } - display_caps[hmi_response::templates_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::templates_available); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::screen_params)) { + display_caps[hmi_response::screen_params] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::screen_params); + } - display_caps[hmi_response::screen_params] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::screen_params); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::num_custom_presets_available)) { + display_caps[hmi_response::num_custom_presets_available] = + hmi_capabilities.display_capabilities()->getElement( + hmi_response::num_custom_presets_available); + } - display_caps[hmi_response::num_custom_presets_available] = - hmi_capabilities.display_capabilities()->getElement( - hmi_response::num_custom_presets_available); + if (hmi_capabilities.display_capabilities()->keyExists( + hmi_response::image_capabilities)) { + display_caps[hmi_response::graphic_supported] = + (hmi_capabilities.display_capabilities() + ->getElement(hmi_response::image_capabilities) + .length() > 0); + } } if (hmi_capabilities.audio_pass_thru_capabilities()) { @@ -684,9 +726,9 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( } } if ((mobile_apis::Result::SUCCESS == result_code) && - (mobile_apis::Result::INVALID_ENUM != result_checking_app_hmi_type_)) { + (mobile_apis::Result::INVALID_ENUM != result_code_)) { add_info += response_info_; - result_code = result_checking_app_hmi_type_; + result_code = result_code_; } // in case application exist in resumption we need to send resumeVrgrammars @@ -710,6 +752,10 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( } policy::StatusNotifier notify_upd_manager = GetPolicyHandler().AddApplication( application->policy_app_id(), hmi_types); + + response_params[strings::icon_resumed] = + file_system::FileExists(application->app_icon_path()); + SendResponse(true, result_code, add_info.c_str(), &response_params); SendOnAppRegisteredNotificationToHMI( *(application.get()), resumption, need_restore_vr); @@ -813,8 +859,9 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( msg_params[strings::tts_name] = *(application_impl.tts_name()); } + const std::string policy_app_id = application_impl.policy_app_id(); std::string priority; - GetPolicyHandler().GetPriority(application_impl.policy_app_id(), &priority); + GetPolicyHandler().GetPriority(policy_app_id, &priority); if (!priority.empty()) { msg_params[strings::priority] = MessageHelper::GetPriorityCode(priority); @@ -824,8 +871,10 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( smart_objects::SmartObject& application = msg_params[strings::application]; application[strings::app_name] = application_impl.name(); application[strings::app_id] = application_impl.app_id(); - application[hmi_response::policy_app_id] = application_impl.policy_app_id(); - application[strings::icon] = application_impl.app_icon_path(); + application[hmi_response::policy_app_id] = policy_app_id; + if (file_system::FileExists(application_impl.app_icon_path())) { + application[strings::icon] = application_impl.app_icon_path(); + } const smart_objects::SmartObject* ngn_media_screen_name = application_impl.ngn_media_screen_name(); @@ -844,18 +893,41 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( application[strings::app_type] = *app_type; } - std::vector<std::string> request_types = - GetPolicyHandler().GetAppRequestTypes(application_impl.policy_app_id()); + const policy::RequestType::State app_request_types_state = + GetPolicyHandler().GetAppRequestTypeState(policy_app_id); + if (policy::RequestType::State::AVAILABLE == app_request_types_state) { + const auto request_types = + GetPolicyHandler().GetAppRequestTypes(policy_app_id); + application[strings::request_type] = SmartObject(SmartType_Array); + smart_objects::SmartObject& request_types_array = + application[strings::request_type]; - application[strings::request_type] = SmartObject(SmartType_Array); - smart_objects::SmartObject& request_array = - application[strings::request_type]; - - uint32_t index = 0; - std::vector<std::string>::const_iterator it = request_types.begin(); - for (; request_types.end() != it; ++it) { - request_array[index] = *it; - ++index; + size_t index = 0; + for (auto it : request_types) { + request_types_array[index] = it; + ++index; + } + } else if (policy::RequestType::State::EMPTY == app_request_types_state) { + application[strings::request_type] = SmartObject(SmartType_Array); + } + + const policy::RequestSubType::State app_request_subtypes_state = + GetPolicyHandler().GetAppRequestSubTypeState(policy_app_id); + if (policy::RequestSubType::State::AVAILABLE == app_request_subtypes_state) { + const auto request_subtypes = + GetPolicyHandler().GetAppRequestSubTypes(policy_app_id); + application[strings::request_subtype] = SmartObject(SmartType_Array); + smart_objects::SmartObject& request_subtypes_array = + application[strings::request_subtype]; + + size_t index = 0; + for (auto it : request_subtypes) { + request_subtypes_array[index] = it; + ++index; + } + } else if (policy::RequestSubType::State::EMPTY == + app_request_subtypes_state) { + application[strings::request_subtype] = SmartObject(SmartType_Array); } const protocol_handler::SessionObserver& session_observer = @@ -880,6 +952,18 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( &secondary_device_info); } + const smart_objects::SmartObject* day_color_scheme = + application_impl.day_color_scheme(); + if (day_color_scheme) { + application[strings::day_color_scheme] = *day_color_scheme; + } + + const smart_objects::SmartObject* night_color_scheme = + application_impl.night_color_scheme(); + if (night_color_scheme) { + application[strings::night_color_scheme] = *night_color_scheme; + } + DCHECK(application_manager_.ManageHMICommand(notification)); } @@ -991,7 +1075,7 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckWithPolicyData() { "Following AppHmiTypes are not present in policy " "table:" + log; - result_checking_app_hmi_type_ = mobile_apis::Result::WARNINGS; + result_code_ = mobile_apis::Result::WARNINGS; } } // Replace AppHmiTypes in request with values allowed by policy table diff --git a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc index ee544e956a..a100bbb5fb 100644 --- a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc @@ -31,9 +31,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include <algorithm> #include "application_manager/commands/mobile/set_app_icon_request.h" +#include <algorithm> + #include "application_manager/message_helper.h" #include "application_manager/application_impl.h" #include "interfaces/MOBILE_API.h" @@ -90,10 +91,6 @@ void SetAppIconRequest::Run() { return; } - if (is_icons_saving_enabled_) { - CopyToIconStorage(full_file_path); - } - smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); @@ -262,6 +259,11 @@ void SetAppIconRequest::on_event(const event_engine::Event& event) { const std::string& path = (*message_)[strings::msg_params][strings::sync_file_name] [strings::value].asString(); + + if (is_icons_saving_enabled_) { + CopyToIconStorage(path); + } + app->set_app_icon_path(path); LOG4CXX_INFO(logger_, diff --git a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc index 38b62ce731..ed60ca4928 100644 --- a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc @@ -48,8 +48,7 @@ SetDisplayLayoutRequest::~SetDisplayLayoutRequest() {} void SetDisplayLayoutRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - ApplicationConstSharedPtr app = - application_manager_.application(connection_key()); + ApplicationSharedPtr app = application_manager_.application(connection_key()); if (!app) { LOG4CXX_ERROR(logger_, "Application is not registered"); @@ -57,6 +56,58 @@ void SetDisplayLayoutRequest::Run() { return; } + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + std::string old_layout = app->display_layout(); + std::string new_layout = ""; + + if (msg_params.keyExists(strings::display_layout)) { + new_layout = msg_params[strings::display_layout].asString(); + } + + if (new_layout != old_layout && + !new_layout.empty()) { // Template switched, allow any color change + LOG4CXX_DEBUG(logger_, + "SetDisplayLayoutRequest New Layout: " << new_layout); + app->set_display_layout(new_layout); + } else { + LOG4CXX_DEBUG(logger_, "SetDisplayLayoutRequest No Layout Change"); + // Template layout is the same as previous layout + // Reject message if colors are set + if (msg_params.keyExists(strings::day_color_scheme) && + app->day_color_scheme() != NULL && + !(msg_params[strings::day_color_scheme] == + *(app->day_color_scheme()))) { + // Color scheme param exists and has been previously set, do not allow + // color change + LOG4CXX_DEBUG(logger_, "Reject Day Color Scheme Change"); + SendResponse(false, mobile_apis::Result::REJECTED); + return; + } + + if (msg_params.keyExists(strings::night_color_scheme) && + app->night_color_scheme() != NULL && + !(msg_params[strings::night_color_scheme] == + *(app->night_color_scheme()))) { + // Color scheme param exists and has been previously set, do not allow + // color change + LOG4CXX_DEBUG(logger_, "Reject Night Color Scheme Change"); + SendResponse(false, mobile_apis::Result::REJECTED); + return; + } + } + + if (msg_params.keyExists(strings::day_color_scheme)) { + LOG4CXX_DEBUG(logger_, "Allow Day Color Scheme Change"); + app->set_day_color_scheme(msg_params[strings::day_color_scheme]); + } + + if (msg_params.keyExists(strings::night_color_scheme)) { + LOG4CXX_DEBUG(logger_, "Allow Night Color Scheme Change"); + app->set_night_color_scheme(msg_params[strings::night_color_scheme]); + } + (*message_)[strings::msg_params][strings::app_id] = app->app_id(); StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetDisplayLayout, diff --git a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc index e811f5d154..621aa90447 100644 --- a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc @@ -31,6 +31,7 @@ */ #include <string.h> +#include <numeric> #include <algorithm> #include "application_manager/commands/mobile/set_global_properties_request.h" @@ -185,14 +186,54 @@ void SetGlobalPropertiesRequest::Run() { smart_objects::SmartObject params = smart_objects::SmartObject(smart_objects::SmartType_Map); + std::vector<std::string> invalid_params; if (is_help_prompt_present) { - app->set_help_prompt(msg_params.getElement(strings::help_prompt)); - params[strings::help_prompt] = (*app->help_prompt()); + smart_objects::SmartObject& help_prompt = + (*message_)[strings::msg_params][strings::help_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(help_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + invalid_params.push_back("help_prompt"); + } else { + app->set_help_prompt(help_prompt); + params[strings::help_prompt] = (*app->help_prompt()); + } } if (is_timeout_prompt_present) { - app->set_timeout_prompt(msg_params.getElement(strings::timeout_prompt)); - params[strings::timeout_prompt] = (*app->timeout_prompt()); + smart_objects::SmartObject& timeout_prompt = + (*message_)[strings::msg_params][strings::timeout_prompt]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles( + timeout_prompt, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + invalid_params.push_back("timeout_prompt"); + } else { + app->set_timeout_prompt(timeout_prompt); + params[strings::timeout_prompt] = (*app->timeout_prompt()); + } + } + + if (!invalid_params.empty()) { + std::string params_list = std::accumulate( + std::begin(invalid_params), + std::end(invalid_params), + std::string(""), + [](std::string& first, std::string& second) { + return first.empty() ? second : first + ", " + second; + }); + const std::string info = + "One or more files needed for " + params_list + " are not present"; + SendResponse(false, mobile_apis::Result::FILE_NOT_FOUND, info.c_str()); + return; } params[strings::app_id] = app->app_id(); diff --git a/src/components/application_manager/src/commands/mobile/speak_request.cc b/src/components/application_manager/src/commands/mobile/speak_request.cc index 1954cde181..6da6b482b3 100644 --- a/src/components/application_manager/src/commands/mobile/speak_request.cc +++ b/src/components/application_manager/src/commands/mobile/speak_request.cc @@ -69,6 +69,21 @@ void SpeakRequest::Run() { return; } + smart_objects::SmartObject& tts_chunks = + (*message_)[strings::msg_params][strings::tts_chunks]; + mobile_apis::Result::eType verification_result = + MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_); + + if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) { + LOG4CXX_ERROR(logger_, + "MessageHelper::VerifyTtsFiles return " + << verification_result); + SendResponse(false, + mobile_apis::Result::FILE_NOT_FOUND, + "One or more files needed for tts_chunks are not present"); + return; + } + (*message_)[strings::msg_params][strings::app_id] = app->app_id(); (*message_)[strings::msg_params][hmi_request::speak_type] = hmi_apis::Common_MethodName::SPEAK; diff --git a/src/components/application_manager/src/commands/mobile/system_request.cc b/src/components/application_manager/src/commands/mobile/system_request.cc index fe38b93732..f0331d0ced 100644 --- a/src/components/application_manager/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/src/commands/mobile/system_request.cc @@ -41,6 +41,7 @@ Copyright (c) 2013, Ford Motor Company #include "application_manager/policies/policy_handler_interface.h" #include "interfaces/MOBILE_API.h" #include "utils/file_system.h" +#include "policy/policy_table/enums.h" #include "formatters/CFormatterJsonBase.h" #include "json/json.h" #include "utils/helpers.h" @@ -454,17 +455,43 @@ void SystemRequest::Run() { const policy::PolicyHandlerInterface& policy_handler = application_manager_.GetPolicyHandler(); + + const std::string stringified_request_type = + rpc::policy_table_interface_base::EnumToJsonString( + static_cast<rpc::policy_table_interface_base::RequestType>( + request_type)); + if (!policy_handler.IsRequestTypeAllowed(application->policy_app_id(), request_type)) { + LOG4CXX_ERROR(logger_, + "RequestType " << stringified_request_type + << " is DISALLOWED by policies"); SendResponse(false, mobile_apis::Result::DISALLOWED); return; } + LOG4CXX_TRACE(logger_, + "RequestType " << stringified_request_type << " is ALLOWED"); + + const bool request_subtype_present = + (*message_)[strings::msg_params].keyExists(strings::request_subtype); + if (request_subtype_present) { + const std::string request_subtype = + (*message_)[strings::msg_params][strings::request_subtype].asString(); + if (!policy_handler.IsRequestSubTypeAllowed(application->policy_app_id(), + request_subtype)) { + LOG4CXX_ERROR(logger_, + "Request subtype: " << request_subtype + << " is DISALLOWED by policies"); + SendResponse(false, mobile_apis::Result::DISALLOWED); + return; + } + LOG4CXX_TRACE(logger_, + "Request subtype: " << request_subtype << " is ALLOWED"); + } - std::string file_name; + std::string file_name = kSYNC; if ((*message_)[strings::msg_params].keyExists(strings::file_name)) { file_name = (*message_)[strings::msg_params][strings::file_name].asString(); - } else { - file_name = kSYNC; } if (!CheckSyntax(file_name)) { @@ -481,8 +508,8 @@ void SystemRequest::Run() { return; } - bool is_system_file = std::string::npos != file_name.find(kSYNC) || - std::string::npos != file_name.find(kIVSU); + const bool is_system_file = std::string::npos != file_name.find(kSYNC) || + std::string::npos != file_name.find(kIVSU); // to avoid override existing file if (is_system_file) { @@ -587,6 +614,10 @@ void SystemRequest::Run() { msg_params[strings::request_type] = (*message_)[strings::msg_params][strings::request_type]; + if (request_subtype_present) { + msg_params[strings::request_subtype] = + (*message_)[strings::msg_params][strings::request_subtype]; + } StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_BasicCommunication); SendHMIRequest(hmi_apis::FunctionID::BasicCommunication_SystemRequest, &msg_params, diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index e39b728155..d00fc2ae19 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -93,6 +93,8 @@ void InitCapabilities() { hmi_apis::Common_SpeechCapabilities::PRE_RECORDED)); tts_enum_capabilities.insert(std::make_pair( std::string("SILENCE"), hmi_apis::Common_SpeechCapabilities::SILENCE)); + tts_enum_capabilities.insert(std::make_pair( + std::string("FILE"), hmi_apis::Common_SpeechCapabilities::FILE)); button_enum_name.insert( std::make_pair(std::string("OK"), hmi_apis::Common_ButtonName::OK)); @@ -282,6 +284,9 @@ void InitCapabilities() { image_field_name_enum.insert(std::make_pair( std::string("graphic"), hmi_apis::Common_ImageFieldName::graphic)); image_field_name_enum.insert( + std::make_pair(std::string("secondaryGraphic"), + hmi_apis::Common_ImageFieldName::secondaryGraphic)); + image_field_name_enum.insert( std::make_pair(std::string("showConstantTBTIcon"), hmi_apis::Common_ImageFieldName::showConstantTBTIcon)); image_field_name_enum.insert(std::make_pair( @@ -548,10 +553,15 @@ void HMICapabilitiesImpl::set_vr_supported_languages( void HMICapabilitiesImpl::set_display_capabilities( const smart_objects::SmartObject& display_capabilities) { - if (display_capabilities_) { - delete display_capabilities_; + if (app_mngr_.IsSOStructValid( + hmi_apis::StructIdentifiers::Common_DisplayCapabilities, + display_capabilities)) { + if (display_capabilities_) { + delete display_capabilities_; + } + display_capabilities_ = + new smart_objects::SmartObject(display_capabilities); } - display_capabilities_ = new smart_objects::SmartObject(display_capabilities); } void HMICapabilitiesImpl::set_hmi_zone_capabilities( diff --git a/src/components/application_manager/src/hmi_command_factory.cc b/src/components/application_manager/src/hmi_command_factory.cc index a7f3ce7e6b..5ef8605999 100644 --- a/src/components/application_manager/src/hmi_command_factory.cc +++ b/src/components/application_manager/src/hmi_command_factory.cc @@ -224,6 +224,7 @@ #include "application_manager/commands/hmi/navi_get_way_points_request.h" #include "application_manager/commands/hmi/navi_get_way_points_response.h" #include "application_manager/commands/hmi/on_ready_notification.h" +#include "application_manager/commands/hmi/on_system_time_ready_notification.h" #include "application_manager/commands/hmi/on_device_chosen_notification.h" #include "application_manager/commands/hmi/on_file_removed_notification.h" #include "application_manager/commands/hmi/on_system_context_notification.h" @@ -269,6 +270,8 @@ #include "application_manager/commands/hmi/on_system_error_notification.h" #include "application_manager/commands/hmi/basic_communication_system_request.h" #include "application_manager/commands/hmi/basic_communication_system_response.h" +#include "application_manager/commands/hmi/basic_communication_get_system_time_request.h" +#include "application_manager/commands/hmi/basic_communication_get_system_time_response.h" #include "application_manager/commands/hmi/basic_communication_on_awake_sdl.h" #include "application_manager/commands/hmi/sdl_policy_update.h" #include "application_manager/commands/hmi/sdl_policy_update_response.h" @@ -1285,6 +1288,11 @@ CommandSharedPtr HMICommandFactory::CreateCommand( new commands::OnReadyNotification(message, application_manager)); break; } + case hmi_apis::FunctionID::BasicCommunication_OnSystemTimeReady: { + command.reset(new commands::OnSystemTimeReadyNotification( + message, application_manager)); + break; + } case hmi_apis::FunctionID::BasicCommunication_OnDeviceChosen: { command.reset(new commands::OnDeviceChosenNotification( message, application_manager)); @@ -2221,6 +2229,16 @@ CommandSharedPtr HMICommandFactory::CreateCommand( } break; } + case hmi_apis::FunctionID::BasicCommunication_GetSystemTime: { + if (is_response) { + command.reset(new commands::BasicCommunicationGetSystemTimeResponse( + message, application_manager)); + } else { + command.reset(new commands::BasicCommunicationGetSystemTimeRequest( + message, application_manager)); + } + break; + } case hmi_apis::FunctionID::Navigation_SendLocation: { if (is_response) { command.reset(new commands::NaviSendLocationResponse( diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index bc1ccd8f42..e1bc2b5125 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -32,11 +32,16 @@ */ #include "application_manager/hmi_state.h" +#include <ostream> +#include <boost/assign.hpp> +#include <boost/bimap.hpp> #include "application_manager/application_manager.h" #include "utils/helpers.h" namespace application_manager { +CREATE_LOGGERPTR_GLOBAL(logger_, "HmiState") + HmiState::HmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr, StateID state_id) @@ -45,7 +50,10 @@ HmiState::HmiState(utils::SharedPtr<Application> app, , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) - , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} + , video_streaming_state_(mobile_apis::VideoStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + LOG4CXX_DEBUG(logger_, *this); +} HmiState::HmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) @@ -54,7 +62,10 @@ HmiState::HmiState(utils::SharedPtr<Application> app, , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) - , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} + , video_streaming_state_(mobile_apis::VideoStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + LOG4CXX_DEBUG(logger_, *this); +} DEPRECATED HmiState::HmiState(uint32_t app_id, const ApplicationManager& app_mngr, @@ -135,13 +146,24 @@ mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state() return expected_state; } +VideoStreamingHmiState::VideoStreamingHmiState( + utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_VIDEO_STREAMING) {} + +mobile_apis::VideoStreamingState::eType +VideoStreamingHmiState::video_streaming_state() const { + if (app_->IsVideoApplication()) { + return parent()->video_streaming_state(); + } + + return mobile_apis::VideoStreamingState::NOT_STREAMABLE; +} + NaviStreamingHmiState::NaviStreamingHmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) - : HmiState(app, app_mngr, STATE_ID_NAVI_STREAMING) {} - -DEPRECATED NaviStreamingHmiState::NaviStreamingHmiState( - uint32_t app_id, const ApplicationManager& app_mngr) - : HmiState(app_id, app_mngr, STATE_ID_NAVI_STREAMING) {} + : VideoStreamingHmiState(app, app_mngr) { + set_state_id(STATE_ID_NAVI_STREAMING); +} mobile_apis::AudioStreamingState::eType NaviStreamingHmiState::audio_streaming_state() const { @@ -149,13 +171,17 @@ NaviStreamingHmiState::audio_streaming_state() const { using namespace mobile_apis; AudioStreamingState::eType expected_state = parent()->audio_streaming_state(); - if (!is_navi_app() && AudioStreamingState::AUDIBLE == expected_state) { + if (!is_navi_app() && Compare<AudioStreamingState::eType, EQ, ONE>( + expected_state, + AudioStreamingState::AUDIBLE, + AudioStreamingState::ATTENUATED)) { if (app_mngr_.is_attenuated_supported()) { expected_state = AudioStreamingState::ATTENUATED; } else { expected_state = AudioStreamingState::NOT_AUDIBLE; } } + return expected_state; } @@ -208,6 +234,7 @@ mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } + return HMILevel::HMI_BACKGROUND; } @@ -220,20 +247,13 @@ DEPRECATED AudioSource::AudioSource(uint32_t app_id, : HmiState(app_id, app_mngr, STATE_ID_AUDIO_SOURCE) {} mobile_apis::HMILevel::eType AudioSource::hmi_level() const { - using namespace mobile_apis; - using namespace helpers; - // TODO(AOleynik): That NONE check is necessary to avoid issue during + // Checking for NONE is necessary to avoid issue during // calculation of HMI level during setting default HMI level - // Should be investigated (used in multiple places here), since looks weird - if (Compare<HMILevel::eType, EQ, ONE>(parent()->hmi_level(), - HMILevel::HMI_BACKGROUND, - HMILevel::HMI_NONE)) { - return parent()->hmi_level(); + if (mobile_apis::HMILevel::HMI_NONE == parent()->hmi_level()) { + return mobile_apis::HMILevel::HMI_NONE; } - if (is_navi_app() || is_voice_communication_app()) { - return HMILevel::HMI_LIMITED; - } - return HMILevel::HMI_BACKGROUND; + + return mobile_apis::HMILevel::HMI_BACKGROUND; } EmbeddedNavi::EmbeddedNavi(utils::SharedPtr<Application> app, @@ -252,9 +272,46 @@ mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } - if (is_media_app()) { - return HMILevel::HMI_LIMITED; - } return HMILevel::HMI_BACKGROUND; } + +namespace { +typedef boost::bimap<HmiState::StateID, std::string> StateID2StrMap; +const StateID2StrMap kStateID2StrMap = + boost::assign::list_of<StateID2StrMap::relation>( + HmiState::StateID::STATE_ID_CURRENT, "CURRENT")( + HmiState::StateID::STATE_ID_REGULAR, "REGULAR")( + HmiState::StateID::STATE_ID_POSTPONED, "POSTPONED")( + HmiState::StateID::STATE_ID_PHONE_CALL, "PHONE_CALL")( + HmiState::StateID::STATE_ID_SAFETY_MODE, "SAFETY_MODE")( + HmiState::StateID::STATE_ID_VR_SESSION, "VR_SESSION")( + HmiState::StateID::STATE_ID_TTS_SESSION, "TTS_SESSION")( + HmiState::StateID::STATE_ID_VIDEO_STREAMING, "VIDEO_STREAMING")( + HmiState::StateID::STATE_ID_NAVI_STREAMING, "NAVI_STREAMING")( + HmiState::StateID::STATE_ID_DEACTIVATE_HMI, "DEACTIVATE_HMI")( + HmiState::StateID::STATE_ID_AUDIO_SOURCE, "AUDIO_SOURCE")( + HmiState::StateID::STATE_ID_EMBEDDED_NAVI, "EMBEDDED_NAVI"); +} // anonymous namespace + +std::ostream& operator<<(std::ostream& os, const HmiState::StateID src) { + try { + os << kStateID2StrMap.left.at(src); + } catch (const std::exception&) { + // specified element have NOT been found + os << "UNRECOGNIZED(" << static_cast<int>(src) << ")"; + } + + return os; +} + +std::ostream& operator<<(std::ostream& os, const HmiState& src) { + os << "HMIState(app id:" << src.app_->app_id() << ", state:" << src.state_id() + << ", hmi_level:" << src.hmi_level() + << ", audio:" << src.audio_streaming_state() + << ", video:" << src.video_streaming_state() + << ", context:" << src.system_context() << ')'; + + return os; } + +} // namespace application_manager diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index c996a245d7..259b3e2a0b 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -175,6 +175,8 @@ std::pair<std::string, mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL_STATE), std::make_pair(strings::instant_fuel_consumption, mobile_apis::VehicleDataType::VEHICLEDATA_FUELCONSUMPTION), + std::make_pair(strings::fuel_range, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELRANGE), std::make_pair(strings::external_temp, mobile_apis::VehicleDataType::VEHICLEDATA_EXTERNTEMP), std::make_pair(strings::vin, mobile_apis::VehicleDataType::VEHICLEDATA_VIN), @@ -217,7 +219,8 @@ std::pair<std::string, mobile_apis::VehicleDataType::VEHICLEDATA_ACCPEDAL), std::make_pair(strings::steering_wheel_angle, mobile_apis::VehicleDataType::VEHICLEDATA_STEERINGWHEEL), -}; + std::make_pair(strings::engine_oil_life, + mobile_apis::VehicleDataType::VEHICLEDATA_ENGINEOILLIFE)}; const VehicleData MessageHelper::vehicle_data_( kVehicleDataInitializer, @@ -365,6 +368,20 @@ void MessageHelper::SendDecryptCertificateToHMI(const std::string& file_name, app_mngr.ManageHMICommand(message); } +void MessageHelper::SendGetSystemTimeRequest(const uint32_t correlation_id, + ApplicationManager& app_mngr) { + using namespace smart_objects; + SmartObjectSPtr message = + CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); + + DCHECK(message); + + (*message)[strings::params][strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_GetSystemTime; + + app_mngr.ManageHMICommand(message); +} + void MessageHelper::SendHashUpdateNotification(const uint32_t app_id, ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); @@ -1711,6 +1728,9 @@ bool MessageHelper::CreateHMIApplicationStruct( const smart_objects::SmartObject* app_types = app->app_types(); const smart_objects::SmartObject* ngn_media_screen_name = app->ngn_media_screen_name(); + const smart_objects::SmartObject* day_color_scheme = app->day_color_scheme(); + const smart_objects::SmartObject* night_color_scheme = + app->night_color_scheme(); message = smart_objects::SmartObject(smart_objects::SmartType_Map); message[strings::app_name] = app->name(); @@ -1739,6 +1759,14 @@ bool MessageHelper::CreateHMIApplicationStruct( message[strings::app_type] = *app_types; } + if (day_color_scheme) { + message[strings::day_color_scheme] = *day_color_scheme; + } + + if (night_color_scheme) { + message[strings::night_color_scheme] = *night_color_scheme; + } + message[strings::device_info] = smart_objects::SmartObject(smart_objects::SmartType_Map); smart_objects::SmartObject& device_info = message[strings::device_info]; @@ -2621,12 +2649,23 @@ void MessageHelper::SendOnAppPermissionsChangedNotification( if (permissions.requestTypeChanged) { smart_objects::SmartObject request_types_array( smart_objects::SmartType_Array); - ; + for (uint16_t index = 0; index < permissions.requestType.size(); ++index) { request_types_array[index] = permissions.requestType[index]; } message[strings::msg_params][strings::request_type] = request_types_array; } + if (permissions.requestSubTypeChanged) { + smart_objects::SmartObject request_subtypes_array( + smart_objects::SmartType_Array); + + for (uint16_t index = 0; index < permissions.requestSubType.size(); + ++index) { + request_subtypes_array[index] = permissions.requestSubType[index]; + } + message[strings::msg_params][strings::request_subtype] = + request_subtypes_array; + } app_mngr.ManageHMICommand( utils::MakeShared<smart_objects::SmartObject>(message)); @@ -2763,11 +2802,23 @@ mobile_apis::Result::eType MessageHelper::VerifyImageApplyPath( } const std::string& file_name = image[strings::value].asString(); + const std::string& full_file_path = GetAppFilePath(file_name, app, app_mngr); + image[strings::value] = full_file_path; + if (file_system::FileExists(full_file_path)) { + return mobile_apis::Result::SUCCESS; + } + return mobile_apis::Result::INVALID_DATA; +} + +std::string MessageHelper::GetAppFilePath(std::string file_name, + ApplicationConstSharedPtr app, + ApplicationManager& app_mngr) { std::string str = file_name; + // Verify that file name is not only space characters str.erase(remove(str.begin(), str.end(), ' '), str.end()); if (0 == str.size()) { - return mobile_apis::Result::INVALID_DATA; + return ""; } std::string full_file_path; @@ -2793,12 +2844,25 @@ mobile_apis::Result::eType MessageHelper::VerifyImageApplyPath( full_file_path += file_name; } - image[strings::value] = full_file_path; - if (!file_system::FileExists(full_file_path)) { - return mobile_apis::Result::INVALID_DATA; - } + return full_file_path; +} - return mobile_apis::Result::SUCCESS; +mobile_apis::Result::eType MessageHelper::VerifyTtsFiles( + smart_objects::SmartObject& tts_chunks, + ApplicationConstSharedPtr app, + ApplicationManager& app_mngr) { + mobile_apis::Result::eType result = mobile_apis::Result::SUCCESS; + for (auto& tts_chunk : *(tts_chunks.asArray())) { + if (tts_chunk[strings::type] == mobile_apis::SpeechCapabilities::FILE) { + const std::string full_file_path = + GetAppFilePath(tts_chunk[strings::text].asString(), app, app_mngr); + tts_chunk[strings::text] = full_file_path; + if (!file_system::FileExists(full_file_path)) { + result = mobile_apis::Result::FILE_NOT_FOUND; + } + } + } + return result; } mobile_apis::Result::eType MessageHelper::VerifyImage( @@ -3042,4 +3106,4 @@ bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) { return true; } -} // namespace application_manager +} // namespace application_manager
\ No newline at end of file diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 4cb4745dc7..d49f4e3af9 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -54,6 +54,7 @@ #include "utils/file_system.h" #include "utils/scope_guard.h" #include "utils/make_shared.h" +#include "utils/helpers.h" #include "policy/policy_manager.h" #ifdef SDL_REMOTE_CONTROL #include "functional_module/plugin_manager.h" @@ -90,7 +91,8 @@ RequestTypeMap TypeToString = { {mobile_apis::RequestType::VEHICLE_DIAGNOSTICS, "VEHICLE_DIAGNOSTICS"}, {mobile_apis::RequestType::EMERGENCY, "EMERGENCY"}, {mobile_apis::RequestType::MEDIA, "MEDIA"}, - {mobile_apis::RequestType::FOTA, "FOTA"}}; + {mobile_apis::RequestType::FOTA, "FOTA"}, + {mobile_apis::RequestType::OEM_SPECIFIC, "OEM_SPECIFIC"}}; const std::string RequestTypeToString(mobile_apis::RequestType::eType type) { RequestTypeMap::const_iterator it = TypeToString.find(type); @@ -162,10 +164,12 @@ struct DeactivateApplication { void operator()(const ApplicationSharedPtr& app) { if (device_id_ == app->device()) { - state_ctrl_.SetRegularState(app, - mobile_apis::HMILevel::HMI_NONE, - mobile_apis::AudioStreamingState::NOT_AUDIBLE, - true); + state_ctrl_.SetRegularState( + app, + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + true); } } @@ -974,6 +978,7 @@ void PolicyHandler::OnPendingPermissionChange( app, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, true); policy_manager_->RemovePendingPermissionChanges(policy_app_id); return; @@ -1024,7 +1029,7 @@ void PolicyHandler::OnPendingPermissionChange( policy_manager_->RemovePendingPermissionChanges(policy_app_id); } - if (permissions.requestTypeChanged) { + if (permissions.requestTypeChanged || permissions.requestSubTypeChanged) { MessageHelper::SendOnAppPermissionsChangedNotification( app->app_id(), permissions, application_manager_); policy_manager_->RemovePendingPermissionChanges(policy_app_id); @@ -1245,12 +1250,15 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( if (is_allowed) { // Send HMI status notification to mobile // Put application in full - AudioStreamingState::eType state = app->is_audio() - ? AudioStreamingState::AUDIBLE - : AudioStreamingState::NOT_AUDIBLE; + AudioStreamingState::eType audio_state = + app->IsAudioApplication() ? AudioStreamingState::AUDIBLE + : AudioStreamingState::NOT_AUDIBLE; + VideoStreamingState::eType video_state = + app->IsVideoApplication() ? VideoStreamingState::STREAMABLE + : VideoStreamingState::NOT_STREAMABLE; application_manager_.state_controller().SetRegularState( - app, mobile_apis::HMILevel::HMI_FULL, state, true); + app, mobile_apis::HMILevel::HMI_FULL, audio_state, video_state, true); last_activated_app_id_ = 0; } else { DeactivateApplication deactivate_notification( @@ -1886,6 +1894,18 @@ void PolicyHandler::OnAppRegisteredOnMobile(const std::string& application_id) { policy_manager_->OnAppRegisteredOnMobile(application_id); } +RequestType::State PolicyHandler::GetAppRequestTypeState( + const std::string& policy_app_id) const { + POLICY_LIB_CHECK(RequestType::State::UNAVAILABLE); + return policy_manager_->GetAppRequestTypesState(policy_app_id); +} + +RequestSubType::State PolicyHandler::GetAppRequestSubTypeState( + const std::string& policy_app_id) const { + POLICY_LIB_CHECK(RequestSubType::State::UNAVAILABLE); + return policy_manager_->GetAppRequestSubTypesState(policy_app_id); +} + bool PolicyHandler::IsRequestTypeAllowed( const std::string& policy_app_id, mobile_apis::RequestType::eType type) const { @@ -1898,17 +1918,66 @@ bool PolicyHandler::IsRequestTypeAllowed( return false; } - std::vector<std::string> request_types = - policy_manager_->GetAppRequestTypes(policy_app_id); + const RequestType::State request_type_state = + policy_manager_->GetAppRequestTypesState(policy_app_id); - // If no request types are assigned to app - any is allowed - if (request_types.empty()) { - return true; + switch (request_type_state) { + case RequestType::State::EMPTY: { + // If empty array of request types is assigned to app - any is allowed + LOG4CXX_TRACE(logger_, "Any Request Type is allowed by policies."); + return true; + } + case RequestType::State::OMITTED: { + // If RequestType parameter omitted for app - any is disallowed + LOG4CXX_TRACE(logger_, "All Request Types are disallowed by policies."); + return false; + } + case RequestType::State::AVAILABLE: { + // If any of request types is available for current application - get them + const auto request_types = + policy_manager_->GetAppRequestTypes(policy_app_id); + return helpers::in_range(request_types, stringified_type); + } + default: + return false; } +} - std::vector<std::string>::const_iterator it = - std::find(request_types.begin(), request_types.end(), stringified_type); - return request_types.end() != it; +bool PolicyHandler::IsRequestSubTypeAllowed( + const std::string& policy_app_id, + const std::string& request_subtype) const { + POLICY_LIB_CHECK(false); + using namespace mobile_apis; + + if (request_subtype.empty()) { + LOG4CXX_ERROR(logger_, "Request subtype to check is empty."); + return false; + } + + const RequestSubType::State request_subtype_state = + policy_manager_->GetAppRequestSubTypesState(policy_app_id); + switch (request_subtype_state) { + case RequestSubType::State::EMPTY: { + // If empty array of request subtypes is assigned to app - any is allowed + LOG4CXX_TRACE(logger_, "Any Request SubType is allowed by policies."); + return true; + } + case RequestSubType::State::OMITTED: { + // If RequestSubType parameter omitted for app - any is disallowed + LOG4CXX_TRACE(logger_, + "All Request SubTypes are disallowed by policies."); + return false; + } + case RequestSubType::State::AVAILABLE: { + // If any of request subtypes is available for current application + // get them all + const auto request_subtypes = + policy_manager_->GetAppRequestSubTypes(policy_app_id); + return helpers::in_range(request_subtypes, request_subtype); + } + default: + return false; + } } const std::vector<std::string> PolicyHandler::GetAppRequestTypes( @@ -1917,6 +1986,12 @@ const std::vector<std::string> PolicyHandler::GetAppRequestTypes( return policy_manager_->GetAppRequestTypes(policy_app_id); } +const std::vector<std::string> PolicyHandler::GetAppRequestSubTypes( + const std::string& policy_app_id) const { + POLICY_LIB_CHECK(std::vector<std::string>()); + return policy_manager_->GetAppRequestSubTypes(policy_app_id); +} + const VehicleInfo policy::PolicyHandler::GetVehicleInfo() const { POLICY_LIB_CHECK(VehicleInfo()); return policy_manager_->GetVehicleInfo(); diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc index 1b9bd7ffb9..f341967842 100644 --- a/src/components/application_manager/src/request_controller.cc +++ b/src/components/application_manager/src/request_controller.cc @@ -50,6 +50,7 @@ RequestController::RequestController(const RequestControlerSettings& settings) : pool_state_(UNDEFINED) , pool_size_(settings.thread_pool_size()) , request_tracker_(settings) + , duplicate_message_count_() , timer_("AM RequestCtrlTimer", new timer::TimerTaskImpl<RequestController>( this, &RequestController::TimeoutThread)) @@ -230,6 +231,21 @@ void RequestController::TerminateRequest(const uint32_t correlation_id, << correlation_id << " connection_key = " << connection_key << " function_id = " << function_id << " force_terminate = " << force_terminate); + { + AutoLock auto_lock(duplicate_message_count_lock_); + auto dup_it = duplicate_message_count_.find(correlation_id); + if (duplicate_message_count_.end() != dup_it) { + duplicate_message_count_[correlation_id]--; + if (0 == duplicate_message_count_[correlation_id]) { + duplicate_message_count_.erase(dup_it); + } + LOG4CXX_DEBUG(logger_, + "Ignoring termination request due to duplicate correlation " + "ID being sent"); + return; + } + } + RequestInfoPtr request = waiting_for_response_.Find(connection_key, correlation_id); if (!request) { @@ -474,7 +490,24 @@ void RequestController::Worker::threadMain() { RequestInfoPtr request_info_ptr = utils::MakeShared<MobileRequestInfo>(request_ptr, timeout_in_mseconds); - request_controller_->waiting_for_response_.Add(request_info_ptr); + if (!request_controller_->waiting_for_response_.Add(request_info_ptr)) { + commands::CommandRequestImpl* cmd_request = + dynamic_cast<commands::CommandRequestImpl*>(request_ptr.get()); + if (cmd_request != NULL) { + uint32_t corr_id = cmd_request->correlation_id(); + request_controller_->duplicate_message_count_lock_.Acquire(); + auto dup_it = + request_controller_->duplicate_message_count_.find(corr_id); + if (request_controller_->duplicate_message_count_.end() == dup_it) { + request_controller_->duplicate_message_count_[corr_id] = 0; + } + request_controller_->duplicate_message_count_[corr_id]++; + request_controller_->duplicate_message_count_lock_.Release(); + cmd_request->SendResponse( + false, mobile_apis::Result::INVALID_ID, "Duplicate correlation_id"); + } + continue; + } LOG4CXX_DEBUG(logger_, "timeout_in_mseconds " << timeout_in_mseconds); if (0 != timeout_in_mseconds) { diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 86a5e0191b..33384f63ce 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -128,6 +128,7 @@ const char* trigger_source = "triggerSource"; const char* hmi_level = "hmiLevel"; const char* activate_app_hmi_level = "level"; const char* audio_streaming_state = "audioStreamingState"; +const char* video_streaming_state = "videoStreamingState"; const char* system_context = "systemContext"; const char* speech_capabilities = "speechCapabilities"; const char* vr_capabilities = "vrCapabilities"; @@ -142,17 +143,30 @@ const char* navigation_capability = "navigationCapability"; const char* phone_capability = "phoneCapability"; const char* video_streaming_capability = "videoStreamingCapability"; const char* rc_capability = "remoteControlCapability"; +const char* day_color_scheme = "dayColorScheme"; +const char* night_color_scheme = "nightColorScheme"; +const char* primary_color = "primaryColor"; +const char* secondary_color = "secondaryColor"; +const char* background_color = "backgroundColor"; +const char* red = "red"; +const char* green = "green"; +const char* blue = "blue"; +const char* display_layout = "displayLayout"; +const char* icon_resumed = "iconResumed"; // PutFile const char* sync_file_name = "syncFileName"; const char* file_name = "fileName"; const char* file_type = "fileType"; const char* file_size = "fileSize"; +const char* crc32_check_sum = "crc"; const char* request_type = "requestType"; +const char* request_subtype = "requestSubType"; const char* persistent_file = "persistentFile"; const char* file_data = "fileData"; const char* space_available = "spaceAvailable"; const char* image_type = "imageType"; +const char* is_template = "isTemplate"; const char* image = "image"; const char* type = "type"; const char* system_file = "systemFile"; @@ -203,6 +217,7 @@ const char* rpm = "rpm"; const char* fuel_level = "fuelLevel"; const char* fuel_level_state = "fuelLevel_State"; const char* instant_fuel_consumption = "instantFuelConsumption"; +const char* fuel_range = "fuelRange"; const char* external_temp = "externalTemperature"; const char* vin = "vin"; const char* prndl = "prndl"; @@ -239,6 +254,7 @@ const char* remote_control = "remoteControl"; const char* sdl_version = "sdlVersion"; const char* system_software_version = "systemSoftwareVersion"; const char* priority = "priority"; +const char* engine_oil_life = "engineOilLife"; // resuming const char* application_commands = "applicationCommands"; @@ -352,7 +368,7 @@ const char* instance_follow_redirect = "InstanceFollowRedirect"; const char* charset = "charset"; const char* content_lenght = "Content_Lenght"; const char* GET = "GET"; -} // http_request +} // namespace http_request namespace mobile_notification { const char* state = "state"; @@ -365,7 +381,17 @@ const char* kFull = "FULL"; const char* kLimited = "LIMITED"; const char* kBackground = "BACKGROUND"; const char* kNone = "NONE"; -} +} // namespace hmi_levels + +namespace time_keys { +const char* millisecond = "millisecond"; +const char* second = "second"; +const char* minute = "minute"; +const char* hour = "hour"; +const char* day = "day"; +const char* month = "month"; +const char* year = "year"; +} // namespace time_keys namespace hmi_request { const char* parent_id = "parentID"; @@ -427,6 +453,7 @@ const char* dtc = "dtc"; const char* ecu_header = "ecuHeader"; const char* image_capabilities = "imageCapabilities"; const char* display_type = "displayType"; +const char* display_name = "displayName"; const char* text_fields = "textFields"; const char* media_clock_formats = "mediaClockFormats"; const char* graphic_supported = "graphicSupported"; @@ -437,7 +464,7 @@ const char* num_custom_presets_available = "numCustomPresetsAvailable"; const char* urls = "urls"; const char* policy_app_id = "policyAppID"; const char* enabled = "enabled"; - +const char* system_time = "systemTime"; } // namespace hmi_response namespace hmi_notification { @@ -452,7 +479,6 @@ const char* policyfile = "policyfile"; const char* is_active = "isActive"; const char* is_deactivated = "isDeactivated"; const char* event_name = "eventName"; - } // namespace hmi_notification } // namespace application_manager diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 84081a3830..9615656675 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -31,6 +31,7 @@ */ #include "application_manager/state_controller_impl.h" +#include <tuple> #include "application_manager/usage_statistics.h" #include "utils/helpers.h" #include "utils/make_shared.h" @@ -40,15 +41,18 @@ namespace application_manager { CREATE_LOGGERPTR_GLOBAL(logger_, "StateControllerImpl") -bool IsStatusChanged(HmiStatePtr old_state, HmiStatePtr new_state) { - if (old_state->hmi_level() != new_state->hmi_level() || - old_state->audio_streaming_state() != - new_state->audio_streaming_state() || - old_state->system_context() != new_state->system_context()) { - return true; - } - return false; +namespace { +bool IsStateChanged(const HmiState& old_state, const HmiState& new_state) { + return std::make_tuple(old_state.hmi_level(), + old_state.audio_streaming_state(), + old_state.video_streaming_state(), + old_state.system_context()) != + std::make_tuple(new_state.hmi_level(), + new_state.audio_streaming_state(), + new_state.video_streaming_state(), + new_state.system_context()); } +} // unnamed namespace StateControllerImpl::StateControllerImpl(ApplicationManager& app_mngr) : EventObserver(app_mngr.event_dispatcher()), app_mngr_(app_mngr) { @@ -64,20 +68,20 @@ StateControllerImpl::StateControllerImpl(ApplicationManager& app_mngr) void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, HmiStatePtr state, const bool send_activate_app) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(state); - DCHECK_OR_RETURN_VOID(state->state_id() == HmiState::STATE_ID_REGULAR); + DCHECK_OR_RETURN_VOID(HmiState::STATE_ID_REGULAR == state->state_id()); + + LOG4CXX_DEBUG(logger_, "Set regular state " << *state); if (state->hmi_level() == mobile_apis::HMILevel::INVALID_ENUM || state->audio_streaming_state() == mobile_apis::AudioStreamingState::INVALID_ENUM || + state->video_streaming_state() == + mobile_apis::VideoStreamingState::INVALID_ENUM || state->system_context() == mobile_apis::SystemContext::INVALID_ENUM) { - LOG4CXX_ERROR(logger_, "Get invalid state"); + LOG4CXX_ERROR(logger_, "Got invalid state"); return; } @@ -91,7 +95,8 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, app->SetPostponedState(state); return; } - hmi_apis::Common_HMILevel::eType hmi_level = + LOG4CXX_DEBUG(logger_, "Resolved state: " << *resolved_state); + const hmi_apis::Common_HMILevel::eType hmi_level = static_cast<hmi_apis::Common_HMILevel::eType>( resolved_state->hmi_level()); @@ -100,7 +105,7 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, if (-1 != corr_id) { subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp, corr_id); - waiting_for_activate[app->app_id()] = resolved_state; + waiting_for_activate_[app->app_id()] = resolved_state; return; } LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp"); @@ -113,13 +118,10 @@ void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const bool send_activate_app) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); HmiStatePtr prev_regular = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = @@ -127,6 +129,7 @@ void StateControllerImpl::SetRegularState( DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(audio_state); + hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(prev_regular->system_context()); SetRegularState(app, hmi_state, send_activate_app); } @@ -136,19 +139,15 @@ void StateControllerImpl::SetRegularState( const mobile_apis::HMILevel::eType hmi_level, const bool send_activate_app) { using namespace mobile_apis; - using namespace helpers; - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); const HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); + hmi_state->set_video_streaming_state(CalcVideoState(app, hmi_level)); hmi_state->set_system_context(SystemContext::SYSCTXT_MAIN); SetRegularState(app, hmi_state, send_activate_app); } @@ -157,37 +156,32 @@ void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, const mobile_apis::SystemContext::eType system_context, const bool send_activate_app) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(audio_state); + hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(system_context); SetRegularState(app, hmi_state, send_activate_app); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); HmiStatePtr prev_state = app->RegularHmiState(); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); + hmi_state->set_video_streaming_state(CalcVideoState(app, hmi_level)); hmi_state->set_system_context(prev_state ? prev_state->system_context() : mobile_apis::SystemContext::SYSCTXT_MAIN); @@ -197,12 +191,8 @@ void StateControllerImpl::SetRegularState( void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, const mobile_apis::SystemContext::eType system_context) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); HmiStatePtr prev_regular = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = @@ -211,19 +201,18 @@ void StateControllerImpl::SetRegularState( hmi_state->set_hmi_level(prev_regular->hmi_level()); hmi_state->set_audio_streaming_state( CalcAudioState(app, prev_regular->hmi_level())); + hmi_state->set_video_streaming_state( + CalcVideoState(app, prev_regular->hmi_level())); hmi_state->set_system_context(system_context); SetRegularState(app, hmi_state, false); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, - const mobile_apis::AudioStreamingState::eType audio_state) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); + const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state) { LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); HmiStatePtr prev_state = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_state); HmiStatePtr hmi_state = @@ -231,18 +220,15 @@ void StateControllerImpl::SetRegularState( DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(prev_state->hmi_level()); hmi_state->set_audio_streaming_state(audio_state); + hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(prev_state->system_context()); SetRegularState(app, hmi_state, false); } void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, HmiStatePtr state) { - CREATE_LOGGERPTR_LOCAL(logger_, "StateControllerImpl"); LOG4CXX_AUTO_TRACE(logger_); - if (!app) { - LOG4CXX_ERROR(logger_, "Invalid application pointer"); - return; - } + DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(state); if (mobile_apis::HMILevel::HMI_FULL == state->hmi_level()) { SetRegularState(app, state, true); @@ -251,84 +237,178 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, } } -void StateControllerImpl::HmiLevelConflictResolver::operator()( - ApplicationSharedPtr to_resolve) { - using namespace mobile_apis; +namespace { + +/** + * @brief IsStreamableHMILevel checks whether the HMI level + * supports audio/video streaming. + * @param val HMI level + * @return true if streamable, false otherwise + */ +bool IsStreamableHMILevel(mobile_apis::HMILevel::eType val) { using namespace helpers; + return Compare<mobile_apis::HMILevel::eType, EQ, ONE>( + val, mobile_apis::HMILevel::HMI_FULL, mobile_apis::HMILevel::HMI_LIMITED); +} + +/** + * @brief IsSameAudioAppType checks whether the both applications: + * 1) belongs to exact HMI type that may stream audio without + * 'isMediaApplication' parameter set to true ('NAVIGATION', 'COMMUNICATION') + * 2) belongs to other HMI types with parameter 'isMediaApplication' + * is set to true. + * 3) are not media. + * @param app1 1st application + * @param app2 2nd application + * @return true if audio applications have same application HMI type + */ +bool IsSameAudioAppType(const Application& app1, const Application& app2) { + const auto is_only_media_app_type = [](const Application& app) { + return app.is_media_application() && !app.is_navi() && + !app.is_voice_communication_supported(); + }; + + const bool both_navi = app1.is_navi() && app2.is_navi(); + const bool both_vc = app1.is_voice_communication_supported() && + app2.is_voice_communication_supported(); + const bool both_media = + is_only_media_app_type(app1) && is_only_media_app_type(app2); + const bool both_other = + !app1.IsAudioApplication() && !app2.IsAudioApplication(); + const bool same_app_audio_type = + both_navi || both_vc || both_media || both_other; + + return same_app_audio_type; +} +} // unnamed namespace + +void StateControllerImpl::HmiLevelConflictResolver::operator()( + ApplicationSharedPtr app_to_resolve) { + DCHECK_OR_RETURN_VOID(app_to_resolve); DCHECK_OR_RETURN_VOID(state_ctrl_); - if (to_resolve == applied_) + DCHECK_OR_RETURN_VOID(applied_); + DCHECK_OR_RETURN_VOID(state_); + + if (applied_ == app_to_resolve) { + // Same app. Nothing to resolve return; - HmiStatePtr cur_state = to_resolve->RegularHmiState(); - - const bool applied_grabs_audio = - Compare<HMILevel::eType, EQ, ONE>( - state_->hmi_level(), HMILevel::HMI_FULL, HMILevel::HMI_LIMITED) && - applied_->IsAudioApplication(); - const bool applied_grabs_full = state_->hmi_level() == HMILevel::HMI_FULL; - const bool to_resolve_handles_full = - cur_state->hmi_level() == HMILevel::HMI_FULL; - const bool to_resolve_handles_audio = - Compare<HMILevel::eType, EQ, ONE>( - cur_state->hmi_level(), HMILevel::HMI_FULL, HMILevel::HMI_LIMITED) && - to_resolve->IsAudioApplication(); - const bool same_app_type = state_ctrl_->IsSameAppType(applied_, to_resolve); - - // If applied Hmi state is FULL: - // all not audio applications will get BACKGROUND - // all applications with same HMI type will get BACKGROUND - // all audio applications with other HMI type(navi, vc, media) in FULL will - // get LIMMITED HMI level - - // If applied Hmi state is LIMITED: - // all applications with other HMI types will save HMI states - // all not audio applications will save HMI states - // all applications with same HMI type will get BACKGROUND - - // If applied Hmi state is BACKGROUND: - // all applications will save HMI states - - HMILevel::eType result_hmi_level = cur_state->hmi_level(); - if (applied_grabs_full && to_resolve_handles_audio && !same_app_type) - result_hmi_level = HMILevel::HMI_LIMITED; - - if ((applied_grabs_full && to_resolve_handles_full && - !to_resolve->IsAudioApplication()) || - (applied_grabs_audio && to_resolve_handles_audio && same_app_type)) - result_hmi_level = HMILevel::HMI_BACKGROUND; - - if (cur_state->hmi_level() != result_hmi_level) { + } + + const HmiStatePtr state_to_resolve = app_to_resolve->RegularHmiState(); + DCHECK_OR_RETURN_VOID(state_to_resolve); + + // If applied HMI state is FULL: + // - all NOT audio/video applications becomes BACKGROUND + // - all audio/video applications with other app type + // (navi, vc, media, projection) in FULL becomes LIMMITED + // - all audio/video applications with same app type becomes BACKGROUND + // + // If applied HMI state is LIMITED: + // - all NOT audio/video applications saves their's HMI states + // - all applications with other app types saves their's HMI states + // - all audio/video applications with same app type becomes BACKGROUND + + if (!IsStreamableHMILevel(state_->hmi_level())) { + LOG4CXX_DEBUG(logger_, + "Applied for app " << applied_->app_id() << " HMI level " + << state_->hmi_level() + << " is NOT streamable. Exit."); + return; + } + + if (!IsStreamableHMILevel(state_to_resolve->hmi_level())) { + LOG4CXX_DEBUG(logger_, + "To resolve app " << app_to_resolve->app_id() << " HMI level " + << state_to_resolve->hmi_level() + << " is NOT streamable. Exit."); + return; + } + + // Applied app constants + const auto applied_hmi_level = state_->hmi_level(); + + const bool applied_grabs_video = + IsStreamableHMILevel(applied_hmi_level) && applied_->IsVideoApplication(); + + // App to resolve constants + const auto to_resolve_hmi_level = state_to_resolve->hmi_level(); + + const bool to_resolve_grabs_audio = + IsStreamableHMILevel(to_resolve_hmi_level) && + app_to_resolve->IsAudioApplication(); + + const bool to_resolve_grabs_video = + IsStreamableHMILevel(to_resolve_hmi_level) && + app_to_resolve->IsVideoApplication(); + + // Compatibility constants + const bool same_app_audio_type = + IsSameAudioAppType(*applied_, *app_to_resolve); + + // Result variables + mobile_apis::VideoStreamingState::eType result_video_state = + mobile_apis::VideoStreamingState::NOT_STREAMABLE; + mobile_apis::AudioStreamingState::eType result_audio_state = + mobile_apis::AudioStreamingState::NOT_AUDIBLE; + + if (to_resolve_grabs_audio && !same_app_audio_type) { + result_audio_state = mobile_apis::AudioStreamingState::AUDIBLE; + } + + if (to_resolve_grabs_video && !applied_grabs_video) { + result_video_state = mobile_apis::VideoStreamingState::STREAMABLE; + } + + mobile_apis::HMILevel::eType result_hmi_level = state_to_resolve->hmi_level(); + + using namespace helpers; + if (mobile_apis::VideoStreamingState::STREAMABLE == result_video_state || + Compare<mobile_apis::AudioStreamingState::eType, EQ, ONE>( + result_audio_state, + mobile_apis::AudioStreamingState::AUDIBLE, + mobile_apis::AudioStreamingState::ATTENUATED)) { + result_hmi_level = mobile_apis::HMILevel::HMI_LIMITED; + } else { + result_hmi_level = mobile_apis::HMILevel::HMI_BACKGROUND; + } + + if (std::make_tuple(to_resolve_hmi_level, + state_to_resolve->audio_streaming_state(), + state_to_resolve->video_streaming_state()) != + std::make_tuple( + result_hmi_level, result_audio_state, result_video_state)) { LOG4CXX_DEBUG(logger_, - "Application " << to_resolve->app_id() - << " will change HMI level to " - << result_hmi_level); - state_ctrl_->SetupRegularHmiState(to_resolve, + "Application " + << app_to_resolve->app_id() << " will change state to: " + << "HMI level " << to_resolve_hmi_level << " --> " + << result_hmi_level << ", audio " + << state_to_resolve->audio_streaming_state() << " --> " + << result_audio_state << ", video " + << state_to_resolve->video_streaming_state() << " --> " + << result_video_state); + state_ctrl_->SetupRegularHmiState(app_to_resolve, result_hmi_level, - result_hmi_level == HMILevel::HMI_LIMITED - ? AudioStreamingState::AUDIBLE - : AudioStreamingState::NOT_AUDIBLE); + result_audio_state, + result_video_state); } else { LOG4CXX_DEBUG(logger_, - "Application " << to_resolve->app_id() - << " will not change HMI level"); + "Application " << app_to_resolve->app_id() + << " will NOT change HMI level"); } } HmiStatePtr StateControllerImpl::ResolveHmiState(ApplicationSharedPtr app, HmiStatePtr state) const { using namespace mobile_apis; - using namespace helpers; LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "State to resolve: hmi_level " - << state->hmi_level() << ", audio_state " - << state->audio_streaming_state() << ", system_context " - << state->system_context()); + LOG4CXX_DEBUG(logger_, "State to resolve: " << *state); HmiStatePtr available_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN(available_state, HmiStatePtr()); available_state->set_hmi_level(state->hmi_level()); available_state->set_audio_streaming_state(state->audio_streaming_state()); + available_state->set_video_streaming_state(state->video_streaming_state()); available_state->set_system_context(state->system_context()); if (app->is_resuming()) { @@ -337,6 +417,8 @@ HmiStatePtr StateControllerImpl::ResolveHmiState(ApplicationSharedPtr app, available_state->set_hmi_level(available_level); available_state->set_audio_streaming_state( CalcAudioState(app, available_level)); + available_state->set_video_streaming_state( + CalcVideoState(app, available_level)); } return IsStateAvailable(app, available_state) ? available_state : HmiStatePtr(); @@ -345,11 +427,8 @@ HmiStatePtr StateControllerImpl::ResolveHmiState(ApplicationSharedPtr app, bool StateControllerImpl::IsResumptionAllowed(ApplicationSharedPtr app, HmiStatePtr state) const { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; using namespace mobile_apis; - if (!app->is_resuming() || - !Compare<HMILevel::eType, EQ, ONE>( - state->hmi_level(), HMILevel::HMI_FULL, HMILevel::HMI_LIMITED)) { + if (!app->is_resuming() || !IsStreamableHMILevel(state->hmi_level())) { LOG4CXX_DEBUG(logger_, "Application is not in resuming mode."); return true; } @@ -375,20 +454,17 @@ bool StateControllerImpl::IsResumptionAllowed(ApplicationSharedPtr app, mobile_apis::HMILevel::eType StateControllerImpl::GetAvailableHmiLevel( ApplicationSharedPtr app, mobile_apis::HMILevel::eType hmi_level) const { - using namespace mobile_apis; - using namespace helpers; LOG4CXX_AUTO_TRACE(logger_); mobile_apis::HMILevel::eType result = hmi_level; - if (!Compare<HMILevel::eType, EQ, ONE>( - hmi_level, HMILevel::HMI_FULL, HMILevel::HMI_LIMITED)) { + if (!IsStreamableHMILevel(hmi_level)) { return result; } const bool is_audio_app = app->IsAudioApplication(); const bool does_audio_app_with_same_type_exist = app_mngr_.IsAppTypeExistsInFullOrLimited(app); - if (HMILevel::HMI_LIMITED == hmi_level) { + if (mobile_apis::HMILevel::HMI_LIMITED == hmi_level) { if (!is_audio_app || does_audio_app_with_same_type_exist) { result = app_mngr_.GetDefaultHmiLevel(app); } @@ -424,13 +500,8 @@ mobile_apis::HMILevel::eType StateControllerImpl::GetAvailableHmiLevel( bool StateControllerImpl::IsStateAvailable(ApplicationSharedPtr app, HmiStatePtr state) const { using namespace mobile_apis; - using namespace helpers; LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "Checking state: hmi_level " - << state->hmi_level() << ", audio_state " - << state->audio_streaming_state() << ", system_context " - << state->system_context()); + LOG4CXX_DEBUG(logger_, "Checking state: " << *state); if (app->is_resuming()) { return IsStateAvailableForResumption(app, state); @@ -454,11 +525,8 @@ bool StateControllerImpl::IsStateAvailableForResumption( ApplicationSharedPtr app, HmiStatePtr state) const { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis; - using namespace helpers; - if (!app->is_resuming() || - !Compare<HMILevel::eType, EQ, ONE>( - state->hmi_level(), HMILevel::HMI_FULL, HMILevel::HMI_LIMITED)) { + if (!app->is_resuming() || !IsStreamableHMILevel(state->hmi_level())) { LOG4CXX_DEBUG(logger_, "Application is not in resuming mode." << " Requested state is available"); @@ -492,20 +560,17 @@ bool StateControllerImpl::IsStateAvailableForResumption( void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, HmiStatePtr state) { - namespace HMILevel = mobile_apis::HMILevel; - namespace AudioStreamingState = mobile_apis::AudioStreamingState; + using namespace mobile_apis; LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(state); - LOG4CXX_DEBUG(logger_, - "hmi_level " << state->hmi_level() << ", audio_state " - << state->audio_streaming_state() - << ", system_context " << state->system_context()); + LOG4CXX_DEBUG(logger_, "Setup regular state: " << *state); HmiStatePtr curr_state = app->CurrentHmiState(); HmiStatePtr old_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(old_state); old_state->set_hmi_level(curr_state->hmi_level()); old_state->set_audio_streaming_state(curr_state->audio_streaming_state()); + old_state->set_video_streaming_state(curr_state->video_streaming_state()); old_state->set_system_context(curr_state->system_context()); app->SetRegularState(state); @@ -524,10 +589,8 @@ void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, void StateControllerImpl::SetupRegularHmiState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level, - const mobile_apis::AudioStreamingState::eType audio_state) { - namespace HMILevel = mobile_apis::HMILevel; - namespace AudioStreamingState = mobile_apis::AudioStreamingState; - using helpers::Compare; + const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); HmiStatePtr prev_state = app->RegularHmiState(); @@ -537,6 +600,7 @@ void StateControllerImpl::SetupRegularHmiState( DCHECK_OR_RETURN_VOID(new_state); new_state->set_hmi_level(hmi_level); new_state->set_audio_streaming_state(audio_state); + new_state->set_video_streaming_state(video_state); new_state->set_system_context(prev_state->system_context()); SetupRegularHmiState(app, new_state); } @@ -547,28 +611,12 @@ void StateControllerImpl::ApplyRegularState(ApplicationSharedPtr app, DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(state); DCHECK_OR_RETURN_VOID(state->state_id() == HmiState::STATE_ID_REGULAR); + LOG4CXX_DEBUG(logger_, + "Applying to app " << app->app_id() << " state " << *state); SetupRegularHmiState(app, state); - ForEachApplication<HmiLevelConflictResolver>( - HmiLevelConflictResolver(app, state, this)); -} - -bool StateControllerImpl::IsSameAppType(ApplicationConstSharedPtr app1, - ApplicationConstSharedPtr app2) { - const bool both_media = - app1->is_media_application() && app2->is_media_application(); - - const bool both_navi = app1->is_navi() && app2->is_navi(); - - const bool both_vc = app1->is_voice_communication_supported() && - app2->is_voice_communication_supported(); - - const bool both_simple = - !app1->IsAudioApplication() && !app2->IsAudioApplication(); - - const bool both_projection = - app1->mobile_projection_enabled() && app2->mobile_projection_enabled(); - - return both_simple || both_media || both_navi || both_vc || both_projection; + LOG4CXX_DEBUG(logger_, + "Resolving HMI level conflicts for app " << app->app_id()); + ForEachApplication(HmiLevelConflictResolver(app, state, this)); } void StateControllerImpl::on_event(const event_engine::Event& event) { @@ -615,7 +663,7 @@ void StateControllerImpl::on_event(const event_engine::Event& event) { const uint32_t id = message[strings::msg_params][hmi_notification::event_name].asUInt(); // TODO(AOleynik): Add verification/conversion check here - Common_EventTypes::eType state_id = + const Common_EventTypes::eType state_id = static_cast<Common_EventTypes::eType>(id); if (is_active) { if (Common_EventTypes::AUDIO_SOURCE == state_id) { @@ -660,6 +708,9 @@ void StateControllerImpl::on_event(const event_engine::Event& event) { break; } } + + LOG4CXX_WARN(logger_, + "Couldn't recognize state id (val='" << state_id << "')"); break; } default: @@ -674,17 +725,9 @@ void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(old_state); DCHECK_OR_RETURN_VOID(new_state); - LOG4CXX_DEBUG(logger_, - "old: hmi_level " << old_state->hmi_level() << ", audio_state " - << old_state->audio_streaming_state() - << ", system_context " - << old_state->system_context()); - LOG4CXX_DEBUG(logger_, - "new: hmi_level " << new_state->hmi_level() << ", audio_state " - << new_state->audio_streaming_state() - << ", system_context " - << new_state->system_context()); - if (IsStatusChanged(old_state, new_state)) { + LOG4CXX_DEBUG(logger_, "Old state: " << *old_state); + LOG4CXX_DEBUG(logger_, "New state: " << *new_state); + if (IsStateChanged(*old_state, *new_state)) { app_mngr_.SendHMIStatusNotification(app); if (new_state->hmi_level() == mobile_apis::HMILevel::HMI_NONE) { app->ResetDataInNone(); @@ -693,15 +736,13 @@ void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, app->app_id(), old_state->hmi_level(), new_state->hmi_level()); app->usage_report().RecordHmiStateChanged(new_state->hmi_level()); } else { - LOG4CXX_ERROR(logger_, "Status not changed"); + LOG4CXX_ERROR(logger_, "State has NOT been changed."); } } -bool StateControllerImpl::IsTempStateActive(HmiState::StateID ID) const { +bool StateControllerImpl::IsTempStateActive(HmiState::StateID id) const { sync_primitives::AutoLock autolock(active_states_lock_); - StateIDList::const_iterator itr = - std::find(active_states_.begin(), active_states_.end(), ID); - return active_states_.end() != itr; + return helpers::in_range(active_states_, id); } void StateControllerImpl::OnApplicationRegistered( @@ -713,23 +754,25 @@ void StateControllerImpl::OnApplicationRegistered( LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - active_states_lock_.Acquire(); - StateIDList::iterator it = active_states_.begin(); - for (; it != active_states_.end(); ++it) { - HmiStatePtr new_state = CreateHmiState(app, *it); - DCHECK_OR_RETURN_VOID(new_state); - DCHECK_OR_RETURN_VOID(new_state->state_id() != HmiState::STATE_ID_REGULAR); - HmiStatePtr old_hmi_state = app->CurrentHmiState(); - new_state->set_parent(old_hmi_state); - app->AddHMIState(new_state); + { + sync_primitives::AutoLock lck(active_states_lock_); + for (const auto state_id : active_states_) { + HmiStatePtr new_state = CreateHmiState(app, state_id); + DCHECK_OR_RETURN_VOID(new_state); + DCHECK_OR_RETURN_VOID(new_state->state_id() != + HmiState::STATE_ID_REGULAR); + HmiStatePtr old_hmi_state = app->CurrentHmiState(); + new_state->set_parent(old_hmi_state); + app->AddHMIState(new_state); + } } - active_states_lock_.Release(); HmiStatePtr default_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(default_state); default_state->set_hmi_level(default_level); default_state->set_audio_streaming_state(CalcAudioState(app, default_level)); + default_state->set_video_streaming_state(CalcVideoState(app, default_level)); default_state->set_system_context(SystemContext::SYSCTXT_MAIN); HmiStatePtr initial_state = app->RegularHmiState(); @@ -778,16 +821,18 @@ void StateControllerImpl::ApplyPostponedStateForApp(ApplicationSharedPtr app) { } } -void StateControllerImpl::TempStateStarted(HmiState::StateID ID) { +void StateControllerImpl::TempStateStarted(HmiState::StateID id) { LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock autolock(active_states_lock_); - StateIDList::iterator it = - std::find(active_states_.begin(), active_states_.end(), ID); - if (it == active_states_.end()) { - active_states_.push_back(ID); - } else { - LOG4CXX_ERROR(logger_, "StateID " << ID << " is already active"); + + { + sync_primitives::AutoLock autolock(active_states_lock_); + if (!helpers::in_range(active_states_, id)) { + active_states_.push_back(id); + return; + } } + + LOG4CXX_ERROR(logger_, "StateID '" << id << "' is already active"); } void StateControllerImpl::TempStateStopped(HmiState::StateID ID) { @@ -805,16 +850,34 @@ void StateControllerImpl::DeactivateApp(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr regular = app->RegularHmiState(); + const HmiStatePtr regular = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(regular); HmiStatePtr new_regular = utils::MakeShared<HmiState>(*regular); - if (app->IsAudioApplication()) { + LOG4CXX_DEBUG(logger_, "Current HMI level: '" << app->hmi_level() << "'"); + const bool is_audio_app = app->IsAudioApplication(); + const bool is_video_app = app->IsVideoApplication(); + + if (is_audio_app || is_video_app) { + // audio or video app move to HMI level limited new_regular->set_hmi_level(HMILevel::HMI_LIMITED); - new_regular->set_audio_streaming_state(AudioStreamingState::AUDIBLE); + + if (is_audio_app) { + new_regular->set_audio_streaming_state(AudioStreamingState::AUDIBLE); + } else { + new_regular->set_audio_streaming_state(AudioStreamingState::NOT_AUDIBLE); + } + + if (is_video_app) { + new_regular->set_video_streaming_state(VideoStreamingState::STREAMABLE); + } else { + new_regular->set_video_streaming_state( + VideoStreamingState::NOT_STREAMABLE); + } } else { new_regular->set_hmi_level(HMILevel::HMI_BACKGROUND); new_regular->set_audio_streaming_state(AudioStreamingState::NOT_AUDIBLE); + new_regular->set_video_streaming_state(VideoStreamingState::NOT_STREAMABLE); } SetRegularState(app, new_regular, false); @@ -831,7 +894,7 @@ void StateControllerImpl::OnActivateAppResponse( ApplicationSharedPtr application = app_mngr_.application_by_hmi_app(hmi_app_id); if (application && hmi_apis::Common_Result::SUCCESS == code) { - HmiStatePtr pending_state = waiting_for_activate[application->app_id()]; + HmiStatePtr pending_state = waiting_for_activate_[application->app_id()]; DCHECK_OR_RETURN_VOID(pending_state); ApplyRegularState(application, pending_state); } @@ -854,9 +917,7 @@ void StateControllerImpl::OnAppActivated( void StateControllerImpl::OnAppDeactivated( const smart_objects::SmartObject& message) { - using namespace hmi_apis; using namespace mobile_apis; - using namespace helpers; LOG4CXX_AUTO_TRACE(logger_); uint32_t app_id = message[strings::msg_params][strings::app_id].asUInt(); @@ -875,12 +936,22 @@ void StateControllerImpl::OnAppDeactivated( DeactivateApp(app); } -void StateControllerImpl::OnNaviStreamingStarted() { - ApplyTempState<HmiState::STATE_ID_NAVI_STREAMING>(); +void StateControllerImpl::OnVideoStreamingStarted( + ApplicationConstSharedPtr app) { + if (app->is_navi()) { + ApplyTempState<HmiState::STATE_ID_NAVI_STREAMING>(); + } else { + ApplyTempState<HmiState::STATE_ID_VIDEO_STREAMING>(); + } } -void StateControllerImpl::OnNaviStreamingStopped() { - CancelTempState<HmiState::STATE_ID_NAVI_STREAMING>(); +void StateControllerImpl::OnVideoStreamingStopped( + ApplicationConstSharedPtr app) { + if (app->is_navi()) { + CancelTempState<HmiState::STATE_ID_NAVI_STREAMING>(); + } else { + CancelTempState<HmiState::STATE_ID_VIDEO_STREAMING>(); + } } bool StateControllerImpl::IsStateActive(HmiState::StateID state_id) const { @@ -917,6 +988,10 @@ HmiStatePtr StateControllerImpl::CreateHmiState( new_state = MakeShared<TTSHmiState>(app, app_mngr_); break; } + case HmiState::STATE_ID_VIDEO_STREAMING: { + new_state = MakeShared<VideoStreamingHmiState>(app, app_mngr_); + break; + } case HmiState::STATE_ID_NAVI_STREAMING: { new_state = MakeShared<NaviStreamingHmiState>(app, app_mngr_); break; @@ -952,20 +1027,31 @@ HmiStatePtr StateControllerImpl::CreateHmiState( mobile_apis::AudioStreamingState::eType StateControllerImpl::CalcAudioState( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level) const { - namespace HMILevel = mobile_apis::HMILevel; - namespace AudioStreamingState = mobile_apis::AudioStreamingState; - using helpers::Compare; - using helpers::EQ; - using helpers::ONE; - - AudioStreamingState::eType audio_state = AudioStreamingState::NOT_AUDIBLE; - if (Compare<HMILevel::eType, EQ, ONE>( - hmi_level, HMILevel::HMI_FULL, HMILevel::HMI_LIMITED)) { - if (app->IsAudioApplication()) { - audio_state = AudioStreamingState::AUDIBLE; - } + auto state = mobile_apis::AudioStreamingState::NOT_AUDIBLE; + if (IsStreamableHMILevel(hmi_level) && app->IsAudioApplication()) { + state = mobile_apis::AudioStreamingState::AUDIBLE; } - return audio_state; + + LOG4CXX_DEBUG(logger_, + "Calculated audio state of app " + << app->app_id() << " for " << hmi_level << " HMI level is " + << state); + return state; +} + +mobile_apis::VideoStreamingState::eType StateControllerImpl::CalcVideoState( + ApplicationSharedPtr app, + const mobile_apis::HMILevel::eType hmi_level) const { + auto state = mobile_apis::VideoStreamingState::NOT_STREAMABLE; + if (IsStreamableHMILevel(hmi_level) && app->IsVideoApplication()) { + state = mobile_apis::VideoStreamingState::STREAMABLE; + } + + LOG4CXX_DEBUG(logger_, + "Calculated video state of app " + << app->app_id() << " for " << hmi_level << " HMI level is " + << state); + return state; } } // namespace application_manager diff --git a/src/components/application_manager/src/system_time/system_time_handler_impl.cc b/src/components/application_manager/src/system_time/system_time_handler_impl.cc new file mode 100644 index 0000000000..6ae6d3e901 --- /dev/null +++ b/src/components/application_manager/src/system_time/system_time_handler_impl.cc @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/system_time/system_time_handler_impl.h" + +#include <algorithm> + +#include "application_manager/message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "interfaces/HMI_API.h" +#include "utils/logger.h" + +namespace application_manager { + +SystemTimeHandlerImpl::SystemTimeHandlerImpl( + ApplicationManager& application_manager) + : event_engine::EventObserver(application_manager.event_dispatcher()) + , utc_time_can_be_received_(false) + , awaiting_get_system_time_(false) + , system_time_listener_(NULL) + , app_manager_(application_manager) { + LOG4CXX_AUTO_TRACE(logger_); + subscribe_on_event( + hmi_apis::FunctionID::BasicCommunication_OnSystemTimeReady); +} + +SystemTimeHandlerImpl::~SystemTimeHandlerImpl() { + LOG4CXX_AUTO_TRACE(logger_); + unsubscribe_from_all_events(); +} + +void SystemTimeHandlerImpl::DoSystemTimeQuery() { + LOG4CXX_AUTO_TRACE(logger_); + using namespace application_manager; + + sync_primitives::AutoLock lock(state_lock_); + if (!utc_time_can_be_received_) { + LOG4CXX_INFO(logger_, + "Navi module is not yet ready." + << "Will process request once it became ready."); + return; + } + SendTimeRequest(); +} + +void SystemTimeHandlerImpl::DoSubscribe(utils::SystemTimeListener* listener) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK(listener); + sync_primitives::AutoLock lock(system_time_listener_lock_); + system_time_listener_ = listener; +} + +void SystemTimeHandlerImpl::DoUnsubscribe(utils::SystemTimeListener* listener) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(system_time_listener_lock_); + system_time_listener_ = NULL; +} + +time_t SystemTimeHandlerImpl::FetchSystemTime() { + LOG4CXX_AUTO_TRACE(logger_); + return last_time_; +} + +bool SystemTimeHandlerImpl::utc_time_can_be_received() const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(state_lock_); + return utc_time_can_be_received_; +} + +void SystemTimeHandlerImpl::SendTimeRequest() { + LOG4CXX_AUTO_TRACE(logger_); + + if (awaiting_get_system_time_) { + LOG4CXX_WARN(logger_, "Another GetSystemTime request in progress. Skipped"); + return; + } + + using namespace application_manager; + uint32_t correlation_id = app_manager_.GetNextHMICorrelationID(); + subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_GetSystemTime, + correlation_id); + MessageHelper::SendGetSystemTimeRequest(correlation_id, app_manager_); + awaiting_get_system_time_ = true; +} + +void SystemTimeHandlerImpl::on_event( + const application_manager::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace application_manager; + using namespace hmi_apis::FunctionID; + switch (event.id()) { + case BasicCommunication_OnSystemTimeReady: + ProcessSystemTimeReadyNotification(); + break; + case BasicCommunication_GetSystemTime: + ProcessSystemTimeResponse(event); + break; + default: + LOG4CXX_ERROR(logger_, "Unknown Event received"); + break; + } +} + +void SystemTimeHandlerImpl::ProcessSystemTimeReadyNotification() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(state_lock_); + utc_time_can_be_received_ = true; + unsubscribe_from_event( + hmi_apis::FunctionID::BasicCommunication_OnSystemTimeReady); +} + +void SystemTimeHandlerImpl::ProcessSystemTimeResponse( + const application_manager::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& message = event.smart_object(); + const smart_objects::SmartObject& system_time_so = + message[strings::msg_params][hmi_response::system_time]; + + struct tm system_time; + memset(&system_time, 0, sizeof(struct tm)); + + system_time.tm_sec = system_time_so[time_keys::second].asInt(); + system_time.tm_min = system_time_so[time_keys::minute].asInt(); + // According to tm specification of tm type hour should be decreased by 1 + system_time.tm_hour = system_time_so[time_keys::hour].asInt() - 1; + system_time.tm_mday = system_time_so[time_keys::day].asInt(); + // According to tm specification of tm type mon should be decreased by 1 + system_time.tm_mon = system_time_so[time_keys::month].asInt() - 1; + // According to tm specification of tm type + // tm_year - number of years since 1900 + system_time.tm_year = system_time_so[time_keys::year].asInt() - 1900; + + // Normalize and convert time from 'tm' format to 'time_t' + last_time_ = mktime(&system_time); + + sync_primitives::AutoLock lock(system_time_listener_lock_); + if (system_time_listener_) { + system_time_listener_->OnSystemTimeArrived(last_time_); + } + sync_primitives::AutoLock state_lock(state_lock_); + awaiting_get_system_time_ = false; +} + +} // namespace application_manager |