diff options
Diffstat (limited to 'src/components/application_manager/src/policies/policy_handler.cc')
-rw-r--r-- | src/components/application_manager/src/policies/policy_handler.cc | 249 |
1 files changed, 152 insertions, 97 deletions
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index d94a364c8c..ab07151b69 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -126,7 +126,10 @@ struct HMILevelPredicate : level_(level) {} bool operator()(const ApplicationSharedPtr app) const { - return level_ == app->hmi_level() ? true : false; + return level_ == app->hmi_level( + mobile_apis::PredefinedWindows::DEFAULT_WINDOW) + ? true + : false; } private: @@ -165,6 +168,7 @@ struct DeactivateApplication { if (device_id_ == app->device()) { state_ctrl_.SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -177,41 +181,6 @@ struct DeactivateApplication { StateController& state_ctrl_; }; -struct SDLAllowedNotification { - SDLAllowedNotification(const connection_handler::DeviceHandle& device_id, - PolicyManager* policy_manager, - StateController& state_controller) - : device_id_(device_id) - , policy_manager_(policy_manager) - , state_controller_(state_controller) {} - - void operator()(const ApplicationSharedPtr& app) { - DCHECK_OR_RETURN_VOID(policy_manager_); - if (device_id_ == app->device()) { - std::string hmi_level = "NONE"; - mobile_apis::HMILevel::eType default_mobile_hmi; - policy_manager_->GetDefaultHmi(app->policy_app_id(), &hmi_level); - if ("BACKGROUND" == hmi_level) { - default_mobile_hmi = mobile_apis::HMILevel::HMI_BACKGROUND; - } else if ("FULL" == hmi_level) { - default_mobile_hmi = mobile_apis::HMILevel::HMI_FULL; - } else if ("LIMITED" == hmi_level) { - default_mobile_hmi = mobile_apis::HMILevel::HMI_LIMITED; - } else if ("NONE" == hmi_level) { - default_mobile_hmi = mobile_apis::HMILevel::HMI_NONE; - } else { - return; - } - state_controller_.SetRegularState(app, default_mobile_hmi, true); - } - } - - private: - connection_handler::DeviceHandle device_id_; - PolicyManager* policy_manager_; - StateController& state_controller_; -}; - /** * @brief Gets from system list of currently registered applications and * create collection of links device-to-application @@ -505,21 +474,25 @@ void PolicyHandler::OnDeviceConsentChanged(const std::string& device_id, continue; } - policy_manager_->ReactOnUserDevConsentForApp(policy_app_id, is_allowed); + policy_manager_->ReactOnUserDevConsentForApp( + device_handle, policy_app_id, is_allowed); - policy_manager_->SendNotificationOnPermissionsUpdated(policy_app_id); + policy_manager_->SendNotificationOnPermissionsUpdated(device_id, + policy_app_id); } } } void PolicyHandler::SendOnAppPermissionsChanged( - const AppPermissions& permissions, const std::string& policy_app_id) const { + const AppPermissions& permissions, + const std::string& device_id, + const std::string& policy_app_id) const { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG( logger_, "PolicyHandler::SendOnAppPermissionsChanged for " << policy_app_id); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, "No app found for policy app id = " << policy_app_id); return; @@ -553,10 +526,11 @@ struct SmartObjectToInt { }; StatusNotifier PolicyHandler::AddApplication( + const std::string& device_id, const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) { POLICY_LIB_CHECK(std::make_shared<utils::CallNothing>()); - return policy_manager_->AddApplication(application_id, hmi_types); + return policy_manager_->AddApplication(device_id, application_id, hmi_types); } void PolicyHandler::AddDevice(const std::string& device_id, @@ -608,13 +582,9 @@ void PolicyHandler::OnAppPermissionConsentInternal( #endif } } else if (!app_to_device_link_.empty()) { - sync_primitives::AutoLock lock(app_to_device_link_lock_); - std::map<std::string, std::string>::const_iterator it = - app_to_device_link_.begin(); - for (; app_to_device_link_.end() != it; ++it) { - ApplicationSharedPtr app = - application_manager_.application_by_policy_id(it->second); - + const ApplicationSet& accessor = + application_manager_.applications().GetData(); + for (const auto& app : accessor) { // If list of apps sent to HMI for user consents is not the same as // current, // permissions should be set only for coincident to registered apps @@ -625,19 +595,26 @@ void PolicyHandler::OnAppPermissionConsentInternal( continue; } + if (!app->IsRegistered()) { + LOG4CXX_DEBUG(logger_, + "Application " << app->policy_app_id() + << " is not marked as registered."); + continue; + } + DeviceParams device_params = GetDeviceParams( app->device(), application_manager_.connection_handler().get_session_observer()); - if (device_params.device_mac_address != it->first) { + if (device_params.device_mac_address != app->mac_address()) { LOG4CXX_WARN(logger_, "Device_id of application is changed." "Permissions setting skipped."); continue; } - out_permissions.policy_app_id = it->second; - out_permissions.device_id = it->first; + out_permissions.policy_app_id = app->policy_app_id(); + out_permissions.device_id = app->mac_address(); #ifdef EXTERNAL_PROPRIETARY_MODE policy_manager_->SetUserConsentForApp(out_permissions, mode); #else @@ -861,6 +838,15 @@ void PolicyHandler::OnDeviceSwitching(const std::string& device_id_from, policy_manager_->OnDeviceSwitching(device_id_from, device_id_to); } +void PolicyHandler::OnLockScreenDismissalStateChanged() { + LOG4CXX_AUTO_TRACE(logger_); + const auto accessor = application_manager_.applications(); + const auto apps = accessor.GetData(); + for (auto& app : apps) { + application_manager_.SendDriverDistractionState(app); + } +} + void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) { LOG4CXX_AUTO_TRACE(logger_); POLICY_LIB_CHECK_VOID(); @@ -878,10 +864,15 @@ void PolicyHandler::OnUpdateStatusChanged(const std::string& status) { } std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) { LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + DeviceParams device_params = GetDeviceParams( + device_handle, + application_manager_.connection_handler().get_session_observer()); + + ApplicationSharedPtr app = application_manager_.application( + device_params.device_mac_address, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, @@ -889,11 +880,8 @@ std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired( << policy_app_id << "' " "not found within registered applications."); - return ""; + return std::string(); } - DeviceParams device_params = GetDeviceParams( - app->device(), - application_manager_.connection_handler().get_session_observer()); return device_params.device_mac_address; } @@ -951,14 +939,14 @@ void PolicyHandler::OnVehicleDataUpdated( } void PolicyHandler::OnPendingPermissionChange( - const std::string& policy_app_id) { + const std::string& device_id, const std::string& policy_app_id) { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG( logger_, "PolicyHandler::OnPendingPermissionChange for " << policy_app_id); POLICY_LIB_CHECK_VOID(); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, "No app found for " << policy_app_id << " policy app id."); @@ -966,7 +954,7 @@ void PolicyHandler::OnPendingPermissionChange( } AppPermissions permissions = - policy_manager_->GetAppPermissionsChanges(policy_app_id); + policy_manager_->GetAppPermissionsChanges(device_id, policy_app_id); const uint32_t app_id = app->app_id(); @@ -975,6 +963,7 @@ void PolicyHandler::OnPendingPermissionChange( app_id, permissions, application_manager_); application_manager_.state_controller().SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -983,7 +972,8 @@ void PolicyHandler::OnPendingPermissionChange( return; } - mobile_apis::HMILevel::eType app_hmi_level = app->hmi_level(); + mobile_apis::HMILevel::eType app_hmi_level = + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); switch (app_hmi_level) { case mobile_apis::HMILevel::eType::HMI_FULL: @@ -1125,7 +1115,8 @@ struct SDLAlowedNotification { if (app->device() == device_id_) { std::string hmi_level; mobile_apis::HMILevel::eType default_mobile_hmi; - policy_manager_->GetDefaultHmi(app->policy_app_id(), &hmi_level); + policy_manager_->GetDefaultHmi( + app->mac_address(), app->policy_app_id(), &hmi_level); if ("BACKGROUND" == hmi_level) { default_mobile_hmi = mobile_apis::HMILevel::HMI_BACKGROUND; } else if ("FULL" == hmi_level) { @@ -1137,7 +1128,11 @@ struct SDLAlowedNotification { } else { return; } - state_controller_.SetRegularState(app, default_mobile_hmi, true); + state_controller_.SetRegularState( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + default_mobile_hmi, + true); } } @@ -1246,7 +1241,12 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( : VideoStreamingState::NOT_STREAMABLE; application_manager_.state_controller().SetRegularState( - app, mobile_apis::HMILevel::HMI_FULL, audio_state, video_state, true); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_FULL, + audio_state, + video_state, + true); last_activated_app_id_ = 0; } else { DeactivateApplication deactivate_notification( @@ -1282,7 +1282,8 @@ void PolicyHandler::OnActivateApp(uint32_t connection_key, permissions.isSDLAllowed = true; } } else { - permissions = policy_manager_->GetAppPermissionsChanges(policy_app_id); + permissions = policy_manager_->GetAppPermissionsChanges(app->mac_address(), + policy_app_id); #ifdef EXTERNAL_PROPRIETARY_MODE UsageStatistics& usage = app->usage_report(); @@ -1353,24 +1354,26 @@ void PolicyHandler::PTExchangeAtUserRequest(uint32_t correlation_id) { update_status, correlation_id, application_manager_); } -void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, +void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions, const HMILevel& default_hmi) { LOG4CXX_AUTO_TRACE(logger_); - OnPermissionsUpdated(policy_app_id, permissions); + OnPermissionsUpdated(device_id, policy_app_id, permissions); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return; } // The application currently not running (i.e. in NONE) should change HMI // level to default - mobile_apis::HMILevel::eType current_hmi_level = app->hmi_level(); + mobile_apis::HMILevel::eType current_hmi_level = + app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); mobile_apis::HMILevel::eType hmi_level = MessageHelper::StringToHMILevel(default_hmi); @@ -1393,10 +1396,16 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, if (hmi_level == mobile_apis::HMILevel::HMI_FULL) { application_manager_.state_controller().SetRegularState( - app, hmi_level, true); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + hmi_level, + true); } else { application_manager_.state_controller().SetRegularState( - app, hmi_level, false); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + hmi_level, + false); } break; } @@ -1409,15 +1418,16 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, } } -void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, +void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions) { LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return; } @@ -1425,7 +1435,7 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, app->app_id(), permissions, application_manager_); LOG4CXX_DEBUG(logger_, - "Notification sent for application_id:" + "Notification sent for application_id: " << policy_app_id << " and connection_key " << app->app_id()); } @@ -1508,12 +1518,13 @@ bool PolicyHandler::GetPriority(const std::string& policy_app_id, void PolicyHandler::CheckPermissions( const application_manager::ApplicationSharedPtr app, + const application_manager::WindowID window_id, const PTString& rpc, const RPCParams& rpc_params, CheckPermissionResult& result) { POLICY_LIB_CHECK_VOID(); const std::string hmi_level = - MessageHelper::StringifiedHMILevel(app->hmi_level()); + MessageHelper::StringifiedHMILevel(app->hmi_level(window_id)); if (hmi_level.empty()) { LOG4CXX_WARN(logger_, "HMI level for " << app->policy_app_id() << " is invalid, rpc " @@ -1527,13 +1538,8 @@ void PolicyHandler::CheckPermissions( "Checking permissions for " << app->policy_app_id() << " in " << hmi_level << " on device " << device_id << " rpc " << rpc); -#ifdef EXTERNAL_PROPRIETARY_MODE - policy_manager_->CheckPermissions( - app->policy_app_id(), hmi_level, rpc, rpc_params, result); -#else // EXTERNAL_PROPRIETARY_MODE policy_manager_->CheckPermissions( device_id, app->policy_app_id(), hmi_level, rpc, rpc_params, result); -#endif // EXTERNAL_PROPRIETARY_MODE } uint32_t PolicyHandler::GetNotificationsNumber( @@ -1548,10 +1554,11 @@ DeviceConsent PolicyHandler::GetUserConsentForDevice( return policy_manager_->GetUserConsentForDevice(device_id); } -bool PolicyHandler::GetDefaultHmi(const std::string& policy_app_id, +bool PolicyHandler::GetDefaultHmi(const std::string& device_id, + const std::string& policy_app_id, std::string* default_hmi) const { POLICY_LIB_CHECK(false); - return policy_manager_->GetDefaultHmi(policy_app_id, default_hmi); + return policy_manager_->GetDefaultHmi(device_id, policy_app_id, default_hmi); } bool PolicyHandler::GetInitialAppData(const std::string& application_id, @@ -1609,6 +1616,19 @@ void PolicyHandler::OnSystemReady() { policy_manager_->OnSystemReady(); } +const boost::optional<bool> PolicyHandler::LockScreenDismissalEnabledState() + const { + POLICY_LIB_CHECK(boost::optional<bool>()); + return policy_manager_->LockScreenDismissalEnabledState(); +} + +const boost::optional<std::string> +PolicyHandler::LockScreenDismissalWarningMessage( + const std::string& language) const { + POLICY_LIB_CHECK(boost::optional<std::string>()); + return policy_manager_->LockScreenDismissalWarningMessage(language); +} + void PolicyHandler::PTUpdatedAt(Counters counter, int value) { POLICY_LIB_CHECK_VOID(); policy_manager_->PTUpdatedAt(counter, value); @@ -1675,7 +1695,7 @@ custom_str::CustomString PolicyHandler::GetAppName( if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return custom_str::CustomString(""); } return app->name(); @@ -2091,9 +2111,10 @@ void PolicyHandler::OnAppsSearchCompleted(const bool trigger_ptu) { policy_manager_->OnAppsSearchCompleted(trigger_ptu); } -void PolicyHandler::OnAppRegisteredOnMobile(const std::string& application_id) { +void PolicyHandler::OnAppRegisteredOnMobile(const std::string& device_id, + const std::string& application_id) { POLICY_LIB_CHECK_VOID(); - policy_manager_->OnAppRegisteredOnMobile(application_id); + policy_manager_->OnAppRegisteredOnMobile(device_id, application_id); } RequestType::State PolicyHandler::GetAppRequestTypeState( @@ -2109,12 +2130,13 @@ RequestSubType::State PolicyHandler::GetAppRequestSubTypeState( } bool PolicyHandler::IsRequestTypeAllowed( + const transport_manager::DeviceHandle& device_id, const std::string& policy_app_id, mobile_apis::RequestType::eType type) const { POLICY_LIB_CHECK(false); using namespace mobile_apis; - std::string stringified_type = RequestTypeToString(type); + const std::string stringified_type = RequestTypeToString(type); if (stringified_type.empty()) { LOG4CXX_ERROR(logger_, "Unknown request type."); return false; @@ -2137,7 +2159,11 @@ bool PolicyHandler::IsRequestTypeAllowed( case RequestType::State::AVAILABLE: { // If any of request types is available for current application - get them const auto request_types = +#ifdef EXTERNAL_PROPRIETARY_MODE + policy_manager_->GetAppRequestTypes(device_id, policy_app_id); +#else policy_manager_->GetAppRequestTypes(policy_app_id); +#endif return helpers::in_range(request_types, stringified_type); } default: @@ -2183,9 +2209,14 @@ bool PolicyHandler::IsRequestSubTypeAllowed( } const std::vector<std::string> PolicyHandler::GetAppRequestTypes( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) const { POLICY_LIB_CHECK(std::vector<std::string>()); +#ifdef EXTERNAL_PROPRIETARY_MODE + return policy_manager_->GetAppRequestTypes(device_handle, policy_app_id); +#else return policy_manager_->GetAppRequestTypes(policy_app_id); +#endif } const std::vector<std::string> PolicyHandler::GetAppRequestSubTypes( @@ -2238,15 +2269,31 @@ bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx, const ApplicationSharedPtr app = application_manager_.application_by_policy_id(app_data.app_id); - const bool is_registered = (app && (app->IsRegistered())); - const bool is_default = (app_data.app_id == policy::kDefaultId); - const bool is_empty_urls = app_urls.empty(); + if (policy::kDefaultId == app_data.app_id) { + return true; + } + + if (app_urls.empty()) { + return false; + } + + const auto devices_ids = GetDevicesIds(app_data.app_id); + LOG4CXX_TRACE(logger_, + "Count devices: " << devices_ids.size() + << " for app_id: " << app_data.app_id); + for (const auto& device_id : devices_ids) { + ApplicationSharedPtr app = + application_manager_.application(device_id, app_data.app_id); + if (app && (app->IsRegistered())) { + return true; + } + } - return ((is_registered && !is_empty_urls) || is_default); + return false; } std::vector<std::string> PolicyHandler::GetDevicesIds( - const std::string& policy_app_id) { + const std::string& policy_app_id) const { return application_manager_.devices(policy_app_id); } @@ -2254,7 +2301,8 @@ void PolicyHandler::UpdateHMILevel(ApplicationSharedPtr app, mobile_apis::HMILevel::eType level) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - if (app->hmi_level() == mobile_apis::HMILevel::HMI_NONE) { + if (app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW) == + mobile_apis::HMILevel::HMI_NONE) { // If default is FULL, send request to HMI. Notification to mobile will be // sent on response receiving. if (mobile_apis::HMILevel::HMI_FULL == level) { @@ -2266,7 +2314,10 @@ void PolicyHandler::UpdateHMILevel(ApplicationSharedPtr app, // Set application hmi level application_manager_.ChangeAppsHMILevel(app->app_id(), level); // If hmi Level is full, it will be seted after ActivateApp response - MessageHelper::SendHMIStatusNotification(*app, application_manager_); + MessageHelper::SendHMIStatusNotification( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + application_manager_); } } } @@ -2309,7 +2360,10 @@ void PolicyHandler::OnUpdateHMIStatus(const std::string& device_id, << app->app_id() << " to default hmi level " << level); // Set application hmi level application_manager_.ChangeAppsHMILevel(app->app_id(), level); - MessageHelper::SendHMIStatusNotification(*app, application_manager_); + MessageHelper::SendHMIStatusNotification( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + application_manager_); } bool PolicyHandler::GetModuleTypes(const std::string& policy_app_id, @@ -2320,6 +2374,7 @@ bool PolicyHandler::GetModuleTypes(const std::string& policy_app_id, } void PolicyHandler::SetDefaultHmiTypes( + const transport_manager::DeviceHandle& device_handle, const std::string& application_id, const smart_objects::SmartObject* app_types) { LOG4CXX_AUTO_TRACE(logger_); @@ -2332,7 +2387,7 @@ void PolicyHandler::SetDefaultHmiTypes( std::back_inserter(hmi_types), SmartObjectToInt()); } - policy_manager_->SetDefaultHmiTypes(application_id, hmi_types); + policy_manager_->SetDefaultHmiTypes(device_handle, application_id, hmi_types); } bool PolicyHandler::CheckHMIType(const std::string& application_id, |