diff options
Diffstat (limited to 'src/components/application_manager/src/application_manager_impl.cc')
-rw-r--r-- | src/components/application_manager/src/application_manager_impl.cc | 289 |
1 files changed, 165 insertions, 124 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 3a92009d4f..20a53b9780 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -121,17 +121,26 @@ bool device_id_comparator(const std::string& device_id, } /** - * @brief policy_app_id_comparator is predicate to compare policy application - * ids - * @param policy_app_id Policy id of application - * @param app Application pointer - * @return True if policy id of application matches to policy id passed + * @brief PolicyAppIdComparator is struct predicate to compare policy + * application ids & device + * @param device_handle of application + * @param id of application + * @return True if policy id & device_handle of application matches to policy id + * & device_handle passed */ -bool policy_app_id_comparator(const std::string& policy_app_id, - ApplicationSharedPtr app) { - DCHECK_OR_RETURN(app, false); - return app->policy_app_id() == policy_app_id; -} +struct PolicyAppIdComparator { + PolicyAppIdComparator(const connection_handler::DeviceHandle& device_handle, + const std::string& policy_app_id) + : device_handle_(device_handle), policy_app_id_(policy_app_id) {} + bool operator()(const ApplicationSharedPtr app) const { + return app && app->device() == device_handle_ && + app->policy_app_id() == policy_app_id_; + } + + private: + const connection_handler::DeviceHandle& device_handle_; + const std::string& policy_app_id_; +}; uint32_t ApplicationManagerImpl::mobile_corelation_id_ = 0; uint32_t ApplicationManagerImpl::corelation_id_ = 0; @@ -295,7 +304,9 @@ ApplicationSharedPtr ApplicationManagerImpl::active_application() const { } bool LimitedAppPredicate(const ApplicationSharedPtr app) { - return app ? app->hmi_level() == mobile_api::HMILevel::HMI_LIMITED : false; + return app ? app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW) == + mobile_api::HMILevel::HMI_LIMITED + : false; } ApplicationSharedPtr ApplicationManagerImpl::get_limited_media_application() @@ -306,7 +317,8 @@ ApplicationSharedPtr ApplicationManagerImpl::get_limited_media_application() bool LimitedNaviAppPredicate(const ApplicationSharedPtr app) { return app ? (app->is_navi() && - app->hmi_level() == mobile_api::HMILevel::HMI_LIMITED) + app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW) == + mobile_api::HMILevel::HMI_LIMITED) : false; } @@ -318,7 +330,8 @@ ApplicationSharedPtr ApplicationManagerImpl::get_limited_navi_application() bool LimitedVoiceAppPredicate(const ApplicationSharedPtr app) { return app ? (app->is_voice_communication_supported() && - app->hmi_level() == mobile_api::HMILevel::HMI_LIMITED) + app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW) == + mobile_api::HMILevel::HMI_LIMITED) : false; } @@ -340,7 +353,8 @@ ApplicationManagerImpl::applications_with_navi() { bool LimitedMobileProjectionPredicate(const ApplicationSharedPtr app) { return app ? (app->mobile_projection_enabled() && - app->hmi_level() == mobile_api::HMILevel::HMI_LIMITED) + app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW) == + mobile_api::HMILevel::HMI_LIMITED) : false; } @@ -565,12 +579,16 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( HmiStatePtr initial_state = CreateRegularState(std::shared_ptr<Application>(application), + mobile_apis::WindowType::MAIN, mobile_apis::HMILevel::INVALID_ENUM, mobile_apis::AudioStreamingState::INVALID_ENUM, mobile_apis::VideoStreamingState::INVALID_ENUM, mobile_api::SystemContext::SYSCTXT_MAIN); - application->SetInitialState(initial_state); + application->SetInitialState( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + std::string(), // should not be tracked for main window + initial_state); application->set_folder_name(policy_app_id + "_" + application->mac_address()); @@ -726,18 +744,15 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { LOG4CXX_DEBUG(logger_, "Activating application with id:" << app->app_id()); - // remove from resumption if app was activated by user + // Remove from resumption if app was activated by user resume_controller().OnAppActivated(app); + // Activate any app services published by the app GetAppServiceManager().OnAppActivated(app); - 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); + + // Activate main window in state controller + state_ctrl_.ActivateDefaultWindow(app); + return true; } @@ -1305,11 +1320,13 @@ void ApplicationManagerImpl::SetAllAppsAllowed(const bool allowed) { HmiStatePtr ApplicationManagerImpl::CreateRegularState( std::shared_ptr<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 { + const mobile_apis::WindowType::eType window_type, + 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 { HmiStatePtr state(new HmiState(app, *this)); + state->set_window_type(window_type); state->set_hmi_level(hmi_level); state->set_audio_streaming_state(audio_state); state->set_video_streaming_state(video_state); @@ -1631,7 +1648,8 @@ mobile_apis::HMILevel::eType ApplicationManagerImpl::GetDefaultHmiLevel( if (GetPolicyHandler().PolicyEnabled()) { const std::string policy_app_id = application->policy_app_id(); std::string default_hmi_string = ""; - if (GetPolicyHandler().GetDefaultHmi(policy_app_id, &default_hmi_string)) { + if (GetPolicyHandler().GetDefaultHmi( + application->mac_address(), policy_app_id, &default_hmi_string)) { if ("BACKGROUND" == default_hmi_string) { default_hmi = HMILevel::HMI_BACKGROUND; } else if ("FULL" == default_hmi_string) { @@ -1943,7 +1961,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback( return; } - if (IsAppInReconnectMode(app->policy_app_id())) { + if (IsAppInReconnectMode(app->device(), app->policy_app_id())) { LOG4CXX_DEBUG(logger_, "Application is in reconnection list and won't be closed."); return; @@ -2490,8 +2508,24 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, } const std::string policy_app_id(app_data[json::appId].asString()); - ApplicationSharedPtr registered_app = - application_by_policy_id(policy_app_id); + + connection_handler::DeviceHandle device_handle; + if (-1 == connection_handler().get_session_observer().GetDataOnSessionKey( + connection_key, nullptr, nullptr, &device_handle)) { + LOG4CXX_ERROR(logger_, + "Failed to create application: no connection info."); + continue; + } + + std::string device_id; + if (-1 == connection_handler().get_session_observer().GetDataOnDeviceID( + device_handle, nullptr, nullptr, &device_id)) { + LOG4CXX_ERROR(logger_, + "Failed to create application: no connection info."); + continue; + } + + ApplicationSharedPtr registered_app = application(device_id, policy_app_id); if (registered_app) { LOG4CXX_DEBUG(logger_, "Application with the same id: " @@ -2530,22 +2564,9 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, const std::string app_icon_dir(settings_.app_icons_folder()); const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); - connection_handler::DeviceHandle device_id = 0; - - if (-1 == connection_handler().get_session_observer().GetDataOnSessionKey( - connection_key, NULL, NULL, &device_id)) { - LOG4CXX_ERROR(logger_, - "Failed to create application: no connection info."); - continue; - } - - std::string device_mac; - connection_handler().get_session_observer().GetDataOnDeviceID( - device_id, NULL, NULL, &device_mac, NULL); - const uint32_t hmi_app_id = - resume_controller().IsApplicationSaved(policy_app_id, device_mac) - ? resume_controller().GetHMIApplicationID(policy_app_id, device_mac) + resume_controller().IsApplicationSaved(policy_app_id, device_id) + ? resume_controller().GetHMIApplicationID(policy_app_id, device_id) : GenerateNewHMIAppID(); // AppId = 0 because this is query_app(provided by hmi for download, but not @@ -2553,8 +2574,8 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, ApplicationSharedPtr app( new ApplicationImpl(0, policy_app_id, - device_mac, device_id, + device_handle, appName, GetPolicyHandler().GetStatisticManager(), *this)); @@ -3030,6 +3051,7 @@ void ApplicationManagerImpl::OnAppUnauthorized(const uint32_t& app_id) { mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( const ApplicationSharedPtr app, + const WindowID window_id, const std::string& function_id, const RPCParams& rpc_params, CommandParametersPermissions* params_permissions) { @@ -3042,7 +3064,8 @@ mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( DCHECK(app); policy::CheckPermissionResult result; - GetPolicyHandler().CheckPermissions(app, function_id, rpc_params, result); + GetPolicyHandler().CheckPermissions( + app, window_id, function_id, rpc_params, result); if (NULL != params_permissions) { params_permissions->allowed_params = result.list_of_allowed_params; @@ -3050,7 +3073,9 @@ mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( params_permissions->undefined_params = result.list_of_undefined_params; } - if (app->hmi_level() == mobile_apis::HMILevel::HMI_NONE && + // Record statistics for default window only + if (app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW) == + mobile_apis::HMILevel::HMI_NONE && function_id != MessageHelper::StringifiedFunctionID( mobile_apis::FunctionID::UnregisterAppInterfaceID)) { if (result.hmi_level_permitted != policy::kRpcAllowed) { @@ -3061,7 +3086,8 @@ mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( #ifdef ENABLE_LOG const std::string log_msg = "Application: " + app->policy_app_id() + ", RPC: " + function_id + - ", HMI status: " + MessageHelper::StringifiedHMILevel(app->hmi_level()); + ", window_id: " + std::to_string(window_id) + ", HMI status: " + + MessageHelper::StringifiedHMILevel(app->hmi_level(window_id)); #endif // ENABLE_LOG if (result.hmi_level_permitted != policy::kRpcAllowed) { LOG4CXX_WARN(logger_, "Request is blocked by policies. " << log_msg); @@ -3134,7 +3160,10 @@ bool ApplicationManagerImpl::HMILevelAllowsStreaming( LOG4CXX_WARN(logger_, "An application is not registered."); return false; } - return Compare<eType, EQ, ONE>(app->hmi_level(), HMI_FULL, HMI_LIMITED); + return Compare<eType, EQ, ONE>( + app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW), + HMI_FULL, + HMI_LIMITED); } bool ApplicationManagerImpl::CanAppStream( @@ -3303,9 +3332,11 @@ void ApplicationManagerImpl::ProcessPostponedMessages(const uint32_t app_id) { const std::string function_id = MessageHelper::StringifiedFunctionID( static_cast<mobile_apis::FunctionID::eType>( (*message)[strings::params][strings::function_id].asUInt())); + const WindowID window_id = MessageHelper::ExtractWindowIdFromSmartObject( + (*message)[strings::msg_params]); const RPCParams params; const mobile_apis::Result::eType check_result = - CheckPolicyPermissions(app, function_id, params); + CheckPolicyPermissions(app, window_id, function_id, params); if (mobile_api::Result::SUCCESS == check_result) { rpc_service_->ManageMobileCommand(message, commands::Command::SOURCE_SDL); } else { @@ -3360,39 +3391,6 @@ void ApplicationManagerImpl::ProcessApp(const uint32_t app_id, } } -void ApplicationManagerImpl::SendHMIStatusNotification( - const std::shared_ptr<Application> app) { - LOG4CXX_AUTO_TRACE(logger_); - DCHECK_OR_RETURN_VOID(app); - smart_objects::SmartObjectSPtr notification = - std::make_shared<smart_objects::SmartObject>(); - smart_objects::SmartObject& message = *notification; - - message[strings::params][strings::function_id] = - static_cast<int32_t>(mobile_api::FunctionID::OnHMIStatusID); - - message[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); - - message[strings::params][strings::connection_key] = - static_cast<int32_t>(app->app_id()); - - message[strings::msg_params][strings::hmi_level] = - static_cast<int32_t>(app->hmi_level()); - - 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()); - - rpc_service_->ManageMobileCommand(notification, - commands::Command::SOURCE_SDL); -} - void ApplicationManagerImpl::ClearTimerPool() { LOG4CXX_AUTO_TRACE(logger_); @@ -3514,14 +3512,14 @@ bool ApplicationManagerImpl::IsApplicationForbidden( } bool ApplicationManagerImpl::IsAppInReconnectMode( + const connection_handler::DeviceHandle& device_id, const std::string& policy_app_id) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(reregister_wait_list_lock_); return reregister_wait_list_.end() != std::find_if(reregister_wait_list_.begin(), reregister_wait_list_.end(), - std::bind1st(std::ptr_fun(&policy_app_id_comparator), - policy_app_id)); + PolicyAppIdComparator(device_id, policy_app_id)); } policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( @@ -3823,13 +3821,18 @@ void ApplicationManagerImpl::OnUpdateHMIAppType( if (flag_diffirence_app_hmi_type) { (*it)->set_app_types(transform_app_hmi_types); (*it)->ChangeSupportingAppHMIType(); - if ((*it)->hmi_level() == mobile_api::HMILevel::HMI_BACKGROUND) { + const mobile_apis::HMILevel::eType app_hmi_level = + (*it)->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); + if (app_hmi_level == mobile_api::HMILevel::HMI_BACKGROUND) { MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); - } else if (((*it)->hmi_level() == mobile_api::HMILevel::HMI_FULL) || - ((*it)->hmi_level() == mobile_api::HMILevel::HMI_LIMITED)) { + } else if ((app_hmi_level == mobile_api::HMILevel::HMI_FULL) || + (app_hmi_level == mobile_api::HMILevel::HMI_LIMITED)) { MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); state_controller().SetRegularState( - *it, mobile_apis::HMILevel::HMI_BACKGROUND, true); + *it, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_BACKGROUND, + true); } } } @@ -3846,10 +3849,10 @@ void ApplicationManagerImpl::EraseAppFromReconnectionList( const auto policy_app_id = app->policy_app_id(); sync_primitives::AutoLock lock(reregister_wait_list_lock_); - auto app_it = std::find_if( - reregister_wait_list_.begin(), - reregister_wait_list_.end(), - std::bind1st(std::ptr_fun(&policy_app_id_comparator), policy_app_id)); + auto app_it = + std::find_if(reregister_wait_list_.begin(), + reregister_wait_list_.end(), + PolicyAppIdComparator(app->device(), policy_app_id)); if (reregister_wait_list_.end() != app_it) { reregister_wait_list_.erase(app_it); } @@ -3907,30 +3910,72 @@ void ApplicationManagerImpl::SendDriverDistractionState( LOG4CXX_WARN(logger_, "DriverDistractionState is INVALID_ENUM"); return; } - smart_objects::SmartObjectSPtr on_driver_distraction = - std::make_shared<smart_objects::SmartObject>(); - (*on_driver_distraction)[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); - (*on_driver_distraction)[strings::params][strings::function_id] = - mobile_api::FunctionID::OnDriverDistractionID; - (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = - driver_distraction_state(); - (*on_driver_distraction)[strings::params][strings::connection_key] = - application->app_id(); + auto create_notification = [application, this]() { + auto notification = std::make_shared<smart_objects::SmartObject>(); + auto& msg_params = (*notification)[strings::msg_params]; + auto& params = (*notification)[strings::params]; + + params[strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); + params[strings::function_id] = + static_cast<int32_t>(mobile_apis::FunctionID::OnDriverDistractionID); + msg_params[mobile_notification::state] = driver_distraction_state(); + const auto lock_screen_dismissal = + policy_handler_->LockScreenDismissalEnabledState(); + + if (lock_screen_dismissal && + hmi_apis::Common_DriverDistractionState::DD_ON == + driver_distraction_state()) { + bool dismissal_enabled = *lock_screen_dismissal; + if (dismissal_enabled) { + const auto language = + MessageHelper::MobileLanguageToString(application->ui_language()); + + const auto warning_message = + policy_handler_->LockScreenDismissalWarningMessage(language); + // Only allow lock screen dismissal if a warning message is available + if (warning_message && !warning_message->empty()) { + msg_params[mobile_notification::lock_screen_dismissal_warning] = + *warning_message; + } else { + dismissal_enabled = false; + } + } + msg_params[mobile_notification::lock_screen_dismissal_enabled] = + dismissal_enabled; + } + + params[strings::connection_key] = application->app_id(); + return notification; + }; - const std::string function_id = MessageHelper::StringifiedFunctionID( - static_cast<mobile_apis::FunctionID::eType>( - (*on_driver_distraction)[strings::params][strings::function_id] - .asUInt())); const RPCParams params; + const std::string function_id = MessageHelper::StringifiedFunctionID( + mobile_api::FunctionID::OnDriverDistractionID); const mobile_apis::Result::eType check_result = - CheckPolicyPermissions(application, function_id, params); + CheckPolicyPermissions(application, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + function_id, + params); if (mobile_api::Result::SUCCESS == check_result) { - rpc_service_->ManageMobileCommand(on_driver_distraction, + rpc_service_->ManageMobileCommand(create_notification(), commands::Command::SOURCE_SDL); } else { - application->PushMobileMessage(on_driver_distraction); + MobileMessageQueue messages; + application->SwapMobileMessageQueue(messages); + messages.erase( + std::remove_if( + messages.begin(), + messages.end(), + [](smart_objects::SmartObjectSPtr message) { + return (*message)[strings::params][strings::function_id] + .asUInt() == + mobile_apis::FunctionID::OnDriverDistractionID; + }), + messages.end()); + application->SwapMobileMessageQueue(messages); + application->PushMobileMessage(create_notification()); } } @@ -4203,16 +4248,11 @@ bool ApplicationManagerImpl::IsSOStructValid( 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 display_capabilities_so.isValid(); } - return true; + + LOG4CXX_ERROR(logger_, "Could not find struct id: " << struct_id); + return false; } #ifdef BUILD_TESTS @@ -4295,9 +4335,10 @@ void ApplicationManagerImpl::ChangeAppsHMILevel( LOG4CXX_ERROR(logger_, "There is no app with id: " << app_id); return; } - const mobile_apis::HMILevel::eType old_level = app->hmi_level(); + const mobile_apis::HMILevel::eType old_level = + app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW); if (old_level != level) { - app->set_hmi_level(level); + app->set_hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW, level); OnHMILevelChanged(app_id, old_level, level); } else { LOG4CXX_WARN(logger_, "Redundant changing HMI level: " << level); |