diff options
29 files changed, 2198 insertions, 129 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 7eb2d43d84..1e848dadd3 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -405,7 +405,13 @@ class ApplicationManagerImpl void CreatePendingApplication( const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info, - connection_handler::DeviceHandle device_id); + connection_handler::DeviceHandle device_id) OVERRIDE; + + void OnWebEngineDeviceCreated() OVERRIDE; + + void CreatePendingApplication(const std::string& policy_app_id) OVERRIDE; + + void RemovePendingApplication(const std::string& policy_app_id) OVERRIDE; void SetPendingApplicationState( const transport_manager::ConnectionUID connection_id, @@ -1155,6 +1161,8 @@ class ApplicationManagerImpl void ApplyFunctorForEachPlugin( std::function<void(plugin_manager::RPCPlugin&)> functor) OVERRIDE; + void SetVINCode(const std::string& vin_code) OVERRIDE; + private: /** * @brief Adds application to registered applications list and marks it as diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index aff4659323..5d95a2468d 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -380,6 +380,15 @@ class MessageHelper { static void SendOnAppUnregNotificationToHMI(ApplicationConstSharedPtr app, bool is_unexpected_disconnect, ApplicationManager& app_mngr); + /** + * @brief Creates BasicCommunication.OnAppPropertiesChange + * notification to the HMI + * @param policy_app_id unique policy app id + * @param app_mngr application manager + * @return smart object with BC.OnAppPropertiesChange notification + */ + static smart_objects::SmartObjectSPtr CreateOnAppPropertiesChangeNotification( + const std::string& policy_app_id, ApplicationManager& app_mngr); static smart_objects::SmartObjectSPtr GetBCActivateAppRequestToHMI( ApplicationConstSharedPtr app, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h new file mode 100644 index 0000000000..484a82ca4c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/request_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCGetAppPropertiesRequest command class + **/ +class BCGetAppPropertiesRequest : public app_mngr::commands::RequestFromHMI { + public: + /** + * @brief BCGetAppPropertiesRequest class constructor + * + * @param message Incoming SmartObject message + **/ + BCGetAppPropertiesRequest(const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief BCGetAppPropertiesRequest class destructor + **/ + virtual ~BCGetAppPropertiesRequest() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + void FillAppProperties(const std::string& policy_app_id, + smart_objects::SmartObject& out_properties) const; + + DISALLOW_COPY_AND_ASSIGN(BCGetAppPropertiesRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h new file mode 100644 index 0000000000..5634663254 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ + +#include "application_manager/commands/response_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCGetAppPropertiesResponse command class + **/ +class BCGetAppPropertiesResponse : public app_mngr::commands::ResponseToHMI { + public: + /** + * @brief BCGetAppPropertiesResponse class constructor + * + * @param message Incoming SmartObject message + **/ + BCGetAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief BCGetAppPropertiesResponse class destructor + **/ + virtual ~BCGetAppPropertiesResponse() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(BCGetAppPropertiesResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_GET_APP_PROPERTIES_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h new file mode 100644 index 0000000000..491d2196e5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/request_from_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCSetAppPropertiesRequest command class + **/ +class BCSetAppPropertiesRequest : public app_mngr::commands::RequestFromHMI { + public: + /** + * @brief BCSetAppPropertiesRequest class constructor + * + * @param message Incoming SmartObject message + **/ + BCSetAppPropertiesRequest(const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief BCSetAppPropertiesRequest class destructor + **/ + virtual ~BCSetAppPropertiesRequest() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(BCSetAppPropertiesRequest); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h new file mode 100644 index 0000000000..e9872196c9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ + +#include "application_manager/commands/response_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief BCSetAppPropertiesResponse command class + **/ +class BCSetAppPropertiesResponse : public app_mngr::commands::ResponseToHMI { + public: + /** + * @brief BCSetAppPropertiesResponse class constructor + * + * @param message Incoming SmartObject message + **/ + BCSetAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + + /** + * @brief BCSetAppPropertiesResponse class destructor + **/ + virtual ~BCSetAppPropertiesResponse() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(BCSetAppPropertiesResponse); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_BC_SET_APP_PROPERTIES_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h new file mode 100644 index 0000000000..7feb2ef85e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ + +#include "application_manager/commands/notification_to_hmi.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +/** + * @brief OnAppPropertiesChangeNotification command class + **/ +class OnAppPropertiesChangeNotification + : public app_mngr::commands::NotificationToHMI { + public: + /** + * @brief OnAppPropertiesChangeNotification class constructor + * + * @param message Incoming SmartObject message + **/ + OnAppPropertiesChangeNotification( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle); + + /** + * @brief OnAppPropertiesChangeNotification class destructor + **/ + virtual ~OnAppPropertiesChangeNotification() = default; + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(OnAppPropertiesChangeNotification); +}; + +} // namespace commands + +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_APP_PROPERTIES_CHANGE_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc new file mode 100644 index 0000000000..57e4318c8a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_request.cc @@ -0,0 +1,142 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCGetAppPropertiesRequest::BCGetAppPropertiesRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCGetAppPropertiesRequest::FillAppProperties( + const std::string& policy_app_id, + smart_objects::SmartObject& out_properties) const { + LOG4CXX_AUTO_TRACE(logger_); + + policy::AppProperties app_properties; + const bool result = + policy_handler_.GetAppProperties(policy_app_id, app_properties); + + if (!result) { + LOG4CXX_DEBUG( + logger_, + "Failed to get app parameters for policy_app_id: " << policy_app_id); + return; + } + + out_properties[strings::policy_app_id] = policy_app_id; + out_properties[strings::enabled] = app_properties.enabled; + + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + policy_handler_.GetInitialAppData(policy_app_id, &nicknames, &app_hmi_types); + + smart_objects::SmartObject nicknames_array(smart_objects::SmartType_Array); + size_t i = 0; + for (const auto& nickname : nicknames) { + nicknames_array[i++] = nickname; + } + out_properties[strings::nicknames] = nicknames_array; + + if (!app_properties.auth_token.empty()) { + out_properties[strings::auth_token] = app_properties.auth_token; + } + if (!app_properties.transport_type.empty()) { + out_properties[strings::transport_type] = app_properties.transport_type; + } + if (!app_properties.hybrid_app_preference.empty()) { + out_properties[strings::hybrid_app_preference] = + app_properties.hybrid_app_preference; + } + if (!app_properties.endpoint.empty()) { + out_properties[strings::endpoint] = app_properties.endpoint; + } +} + +void BCGetAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + const auto& msg_params = (*message_)[strings::msg_params]; + smart_objects::SmartObject response_params(smart_objects::SmartType_Map); + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + + if (msg_params.keyExists(strings::policy_app_id)) { + const auto policy_app_id = msg_params[strings::policy_app_id].asString(); + FillAppProperties(policy_app_id, properties); + response_params[strings::properties][0] = properties; + + } else { + LOG4CXX_DEBUG(logger_, + "policyAppID was absent in request, all apps properties " + "will be returned."); + const auto app_ids = policy_handler_.GetApplicationPolicyIDs(); + int i = 0; + for (auto& app_id : app_ids) { + FillAppProperties(app_id, properties); + response_params[strings::properties][i++] = properties; + } + } + + if (properties.empty()) { + SendErrorResponse( + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE, + "Requested data not available", + application_manager::commands::Command::SOURCE_SDL_TO_HMI); + return; + } + + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS, + &response_params); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc new file mode 100644 index 0000000000..57949a949b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_get_app_properties_response.cc @@ -0,0 +1,60 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCGetAppPropertiesResponse::BCGetAppPropertiesResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCGetAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc new file mode 100644 index 0000000000..92bfd640c6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_request.cc @@ -0,0 +1,114 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h" +#include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCSetAppPropertiesRequest::BCSetAppPropertiesRequest( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : RequestFromHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCSetAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + const auto& properties = + (*message_)[strings::msg_params][strings::properties]; + + const auto policy_app_id(properties[strings::policy_app_id].asString()); + + const auto properties_change_status = + policy_handler_.GetAppPropertiesStatus(properties, policy_app_id); + + using AppPropertiesState = policy::PolicyHandlerInterface::AppPropertiesState; + const bool are_properties_changed = + AppPropertiesState::NO_CHANGES != properties_change_status; + + const bool is_new_app = policy_handler_.IsNewApplication(policy_app_id); + + policy_handler_.OnSetAppProperties(properties); + SendResponse(true, + (*message_)[strings::params][strings::correlation_id].asUInt(), + hmi_apis::FunctionID::BasicCommunication_SetAppProperties, + hmi_apis::Common_Result::SUCCESS); + + if (are_properties_changed || is_new_app) { + const auto notification = + MessageHelper::CreateOnAppPropertiesChangeNotification( + policy_app_id, application_manager_); + application_manager_.GetRPCService().ManageHMICommand(notification); + } + if (is_new_app) { + LOG4CXX_ERROR(logger_, + "Message contains unknow policyAppId: " + << policy_app_id << ", PTU will be triggered"); + policy_handler_.OnLocalAppAdded(); + } + + auto app_enabled = [this]() -> bool { + auto& properties = (*message_)[strings::msg_params][strings::properties]; + if (properties.keyExists(strings::enabled)) { + return properties[strings::enabled].asBool(); + } + return false; + }; + + const bool enable_flag_switch = + AppPropertiesState::ENABLED_FLAG_SWITCH == properties_change_status; + + if (app_enabled() && (enable_flag_switch || is_new_app)) { + application_manager_.CreatePendingApplication(policy_app_id); + application_manager_.SendUpdateAppList(); + return; + } + + if (enable_flag_switch) { + application_manager_.RemovePendingApplication(policy_app_id); + application_manager_.SendUpdateAppList(); + } +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc new file mode 100644 index 0000000000..928a17d0f8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/bc_set_app_properties_response.cc @@ -0,0 +1,62 @@ +/* + Copyright (c) 2020, Ford Motor Company, Livio + 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 the copyright holders nor the names of their + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h" +#include "application_manager/application_impl.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/rpc_service.h" +#include "interfaces/MOBILE_API.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; +namespace commands { + +BCSetAppPropertiesResponse::BCSetAppPropertiesResponse( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : ResponseToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +void BCSetAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc new file mode 100644 index 0000000000..f1fa703bbb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_app_properties_change_notification.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +OnAppPropertiesChangeNotification::OnAppPropertiesChangeNotification( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : NotificationToHMI(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +void OnAppPropertiesChangeNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendNotification(); +} + +} // namespace commands + +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc index 0b7e611e59..c5e94da378 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc @@ -33,20 +33,10 @@ void GetCloudAppPropertiesRequest::Run() { std::string policy_app_id = (*message_)[strings::msg_params][strings::app_id].asString(); - bool enabled = true; - std::string endpoint; - std::string auth_token; - std::string certificate; - std::string cloud_transport_type; - std::string hybrid_app_preference; - - bool result = policy_handler_.GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + policy::AppProperties app_properties; + + const bool result = + policy_handler_.GetAppProperties(policy_app_id, app_properties); if (!result) { SendResponse(false, @@ -70,19 +60,20 @@ void GetCloudAppPropertiesRequest::Run() { } properties[strings::nicknames] = nicknames_array; properties[strings::app_id] = policy_app_id; - properties[strings::enabled] = enabled; + properties[strings::enabled] = app_properties.enabled; - if (!auth_token.empty()) { - properties[strings::auth_token] = auth_token; + if (!app_properties.auth_token.empty()) { + properties[strings::auth_token] = app_properties.auth_token; } - if (!cloud_transport_type.empty()) { - properties[strings::cloud_transport_type] = cloud_transport_type; + if (!app_properties.transport_type.empty()) { + properties[strings::cloud_transport_type] = app_properties.transport_type; } - if (!hybrid_app_preference.empty()) { - properties[strings::hybrid_app_preference] = hybrid_app_preference; + if (!app_properties.hybrid_app_preference.empty()) { + properties[strings::hybrid_app_preference] = + app_properties.hybrid_app_preference; } - if (!endpoint.empty()) { - properties[strings::endpoint] = endpoint; + if (!app_properties.endpoint.empty()) { + properties[strings::endpoint] = app_properties.endpoint; } response_params[strings::properties] = properties; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc index 3bb1e1c107..680429d3b6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc @@ -1,4 +1,5 @@ #include "sdl_rpc_plugin/commands/mobile/set_cloud_app_properties_request.h" +#include "application_manager/message_helper.h" #include "application_manager/policies/policy_handler_interface.h" namespace sdl_rpc_plugin { @@ -30,9 +31,29 @@ void SetCloudAppPropertiesRequest::Run() { return; } - policy_handler_.OnSetCloudAppProperties(*message_); + const auto& properties = + (*message_)[strings::msg_params][strings::properties]; + + const auto app_id(properties[strings::app_id].asString()); + + const auto properties_change_status = + policy_handler_.GetAppPropertiesStatus(properties, app_id); + + using AppPropertiesState = policy::PolicyHandlerInterface::AppPropertiesState; + const bool is_properties_changed = + AppPropertiesState::NO_CHANGES != properties_change_status; + const bool is_new_app = policy_handler_.IsNewApplication(app_id); + + policy_handler_.OnSetCloudAppProperties(*message_); SendResponse(true, mobile_apis::Result::SUCCESS); + + if (is_properties_changed || is_new_app) { + const auto notification = + MessageHelper::CreateOnAppPropertiesChangeNotification( + app_id, application_manager_); + application_manager_.GetRPCService().ManageHMICommand(notification); + } } void SetCloudAppPropertiesRequest::on_event( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc index 6a231f8e35..b89a8dbd68 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc @@ -256,6 +256,12 @@ #include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification.h" #include "sdl_rpc_plugin/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.h" +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/bc_get_app_properties_response.h" +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/bc_set_app_properties_response.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_properties_change_notification.h" + namespace sdl_rpc_plugin { using namespace application_manager; @@ -904,6 +910,19 @@ CommandCreator& HMICommandFactory::get_creator_factory( : factory.GetCreator< commands::OnBCSystemCapabilityUpdatedNotification>(); } + case hmi_apis::FunctionID::BasicCommunication_GetAppProperties: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::BCGetAppPropertiesRequest>() + : factory.GetCreator<commands::BCGetAppPropertiesResponse>(); + } + case hmi_apis::FunctionID::BasicCommunication_SetAppProperties: { + return hmi_apis::messageType::request == message_type + ? factory.GetCreator<commands::BCSetAppPropertiesRequest>() + : factory.GetCreator<commands::BCSetAppPropertiesResponse>(); + } + case hmi_apis::FunctionID::BasicCommunication_OnAppPropertiesChange: { + return factory.GetCreator<commands::OnAppPropertiesChangeNotification>(); + } default: { return factory.GetCreator<InvalidCommand>(); } } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc new file mode 100644 index 0000000000..0d70226645 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_request_test.cc @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "hmi/bc_get_app_properties_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_get_app_properties_request_test { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; + +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::BCGetAppPropertiesRequest; + +using testing::DoAll; +using testing::Return; +using testing::ReturnRef; +using testing::SaveArg; + +namespace { +const std::string kPolicyAppId = "00001"; +const uint32_t kCorrelationId = 1u; +const auto kSource = am::commands::Command::SOURCE_HMI; + +const std::string kAuthToken = "auth_token"; +const std::string kCertificate = "certificate"; +const std::string kTransportType = "WS"; +const std::string kHybridAppPreference = "local_app"; +const bool kEnabled = true; + +const std::string kNickname1 = "nickname1"; +const std::string kNickname2 = "nickname2"; +} // namespace + +bool CompareAppProperties(const smart_objects::SmartObject& app_propersties_so, + const policy::AppProperties& app_properties) { + return (app_propersties_so[strings::auth_token].asString() == + app_properties.auth_token) && + (app_propersties_so[strings::transport_type].asString() == + app_properties.transport_type) && + (app_propersties_so[strings::hybrid_app_preference].asString() == + app_properties.hybrid_app_preference); +} + +bool CompareNicknames(const smart_objects::SmartObject& nicknames_so, + const policy::StringArray& nicknames) { + if (nicknames_so.length() != nicknames.size()) { + return false; + } + + for (size_t i = 0; i < nicknames_so.length(); ++i) { + if (nicknames_so[i].asString() != nicknames[i]) { + return false; + } + } + return true; +} + +ACTION_P(SetTestAppProperties, app_properties) { + arg1 = app_properties; +} + +ACTION_P(SetTestNickNames, nicknames) { + *arg1 = nicknames; +} + +class BCGetAppPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + BCGetAppPropertiesRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL(app_mngr_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(BCGetAppPropertiesRequestTest, Run_PolicyAppId_Exist_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + // Fills app properties with default test values + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(DoAll( + SetTestAppProperties(policy::AppProperties("", + kCertificate, + kEnabled, + kAuthToken, + kTransportType, + kHybridAppPreference)), + Return(true))); + + // Fills app nicknames with default test values + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(kPolicyAppId, _, _)) + .WillOnce( + DoAll(SetTestNickNames(policy::StringArray{kNickname1, kNickname2}), + Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const smart_objects::SmartObject& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties][0]; + + EXPECT_FALSE(sent_app_properties.empty()); + + const std::string auth_token = + sent_app_properties[strings::auth_token].asString(); + const std::string transport_type = + sent_app_properties[strings::transport_type].asString(); + const std::string hybrid_app_preference = + sent_app_properties[strings::hybrid_app_preference].asString(); + // ENDPOINT should be omitted for local application properties. + EXPECT_FALSE(sent_app_properties.keyExists(strings::endpoint)); + + EXPECT_EQ(kAuthToken, auth_token); + EXPECT_EQ(kTransportType, transport_type); + EXPECT_EQ(kHybridAppPreference, hybrid_app_preference); + + EXPECT_TRUE(sent_app_properties.keyExists(strings::nicknames)); + + const auto nick_names = sent_app_properties[strings::nicknames]; + EXPECT_EQ(kNickname1, nick_names[0].asString()); + EXPECT_EQ(kNickname2, nick_names[1].asString()); +} + +TEST_F(BCGetAppPropertiesRequestTest, + PolicyAppIdExistsInMessage_GetAppPropertiesFailed_UNSUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE), + application_manager::commands::Command::SOURCE_SDL_TO_HMI)) + .WillOnce(Return(true)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F( + BCGetAppPropertiesRequestTest, + Run_PolicyAppIdIsAbsentInMessage_AppParametersAreAbsent_NickNamesAreAbsent_UNSUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + EXPECT_CALL(mock_policy_handler_, GetApplicationPolicyIDs()) + .WillOnce(Return(policy::StringArray())); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(_, _, _)).Times(0); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::DATA_NOT_AVAILABLE), + Command::SOURCE_SDL_TO_HMI)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_FALSE( + (*message_to_hmi)[strings::msg_params].keyExists(strings::properties)); +} + +TEST_F(BCGetAppPropertiesRequestTest, + Run_PolicyAppIdIsAbsentInMessage_ReturnsAllAppProperties_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + const std::string test_policy_app_id1 = "test_policy_app_id1"; + const policy::AppProperties test_app1_properties("", + "cert1", + true, + "auth_token1", + "transport_type1", + "hybrid_app_preference1"); + const policy::StringArray test_nicknames1{"nickname1", "nickname2"}; + + const std::string test_policy_app_id2 = "test_policy_app_id2"; + const policy::AppProperties test_app2_properties("", + "cert2", + false, + "auth_token2", + "transport_type2", + "hybrid_app_preference2"); + const policy::StringArray test_nicknames2{"nickname3", "nickname4"}; + + EXPECT_CALL(mock_policy_handler_, GetApplicationPolicyIDs()) + .WillOnce(Return( + policy::StringArray{test_policy_app_id1, test_policy_app_id2})); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(test_policy_app_id1, _)) + .WillOnce( + DoAll(SetTestAppProperties(test_app1_properties), Return(true))); + EXPECT_CALL(mock_policy_handler_, + GetInitialAppData(test_policy_app_id1, _, _)) + .WillOnce(DoAll(SetTestNickNames(test_nicknames1), Return(true))); + + EXPECT_CALL(mock_policy_handler_, GetAppProperties(test_policy_app_id2, _)) + .WillOnce( + DoAll(SetTestAppProperties(test_app2_properties), Return(true))); + EXPECT_CALL(mock_policy_handler_, + GetInitialAppData(test_policy_app_id2, _, _)) + .WillOnce(DoAll(SetTestNickNames(test_nicknames2), Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const auto& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties]; + + EXPECT_EQ(2u, sent_app_properties.length()); + + // Compare test_app1 app_properties with sent app properties + const auto& sent_test_app1_properties = sent_app_properties[0]; + EXPECT_FALSE(sent_test_app1_properties.keyExists(strings::endpoint)); + EXPECT_TRUE( + CompareAppProperties(sent_test_app1_properties, test_app1_properties)); + + const auto& sent_test_app1_nicknames = + sent_app_properties[0][strings::nicknames]; + EXPECT_TRUE(CompareNicknames(sent_test_app1_nicknames, test_nicknames1)); + + // Compare test_app2 app_properties with sent app properties + const auto& sent_test_app2_properties = sent_app_properties[1]; + EXPECT_FALSE(sent_test_app2_properties.keyExists(strings::endpoint)); + EXPECT_TRUE( + CompareAppProperties(sent_test_app2_properties, test_app2_properties)); + + const auto& sent_test_app2_nicknames = + sent_app_properties[1][strings::nicknames]; + EXPECT_TRUE(CompareNicknames(sent_test_app2_nicknames, test_nicknames2)); +} + +TEST_F(BCGetAppPropertiesRequestTest, + Run_PolicyAppIdExist_NickNamesAreAbsent_SendEmptyArray_SUCCESS) { + auto msg = CreateMessage(); + + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::policy_app_id] = kPolicyAppId; + auto command = CreateCommand<BCGetAppPropertiesRequest>(msg); + + // Fills app properties with default test values + EXPECT_CALL(mock_policy_handler_, GetAppProperties(kPolicyAppId, _)) + .WillOnce(DoAll( + SetTestAppProperties(policy::AppProperties("", + kCertificate, + kEnabled, + kAuthToken, + kTransportType, + kHybridAppPreference)), + Return(true))); + + // In the case when nicknames array is empty, SDL should forward the empty + // array to HMI in the app properties + EXPECT_CALL(mock_policy_handler_, GetInitialAppData(kPolicyAppId, _, _)) + .WillOnce(DoAll(SetTestNickNames(policy::StringArray{}), Return(true))); + + auto message_to_hmi = CreateMessage(); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIMessageParametersAre( + kCorrelationId, + hmi_apis::FunctionID::BasicCommunication_GetAppProperties, + hmi_apis::Common_Result::SUCCESS), + kSource)) + .WillOnce(DoAll(SaveArg<0>(&message_to_hmi), Return(true))); + + ASSERT_TRUE(command->Init()); + command->Run(); + + const auto& sent_app_properties = + (*message_to_hmi)[strings::msg_params][strings::properties]; + + EXPECT_TRUE(sent_app_properties[0].keyExists(strings::nicknames)); + EXPECT_TRUE(sent_app_properties[0][strings::nicknames].empty()); +} + +} // namespace bc_get_app_properties_request_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_response_test.cc new file mode 100644 index 0000000000..f9df8db1e3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_get_app_properties_response_test.cc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the names of the copyright holders nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "hmi/bc_get_app_properties_response.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_get_app_properties_response { + +using sdl_rpc_plugin::commands::BCGetAppPropertiesResponse; + +class BCGetAppPropertiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BCGetAppPropertiesResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<BCGetAppPropertiesResponse> command( + CreateCommand<BCGetAppPropertiesResponse>(msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_get_app_properties_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_request_test.cc new file mode 100644 index 0000000000..67f7246970 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_request_test.cc @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2020 Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the names of the copyright holders 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 "gtest/gtest.h" + +#include "application_manager/policies/policy_handler.h" +#include "hmi/bc_set_app_properties_request.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/policies/policy_handler.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_set_app_properties_request { + +namespace am = ::application_manager; +namespace strings = am::strings; + +using sdl_rpc_plugin::commands::BCSetAppPropertiesRequest; +using ::testing::_; +using ::testing::ReturnRef; + +namespace { +const uint32_t kAppId = 1u; +const std::string kPolicyAppId = "00001"; +const std::string kToken = "TOKEN"; +const uint32_t kHmiAppId = 13u; +const uint32_t kCorrelationId = 1u; +const auto kSource = am::commands::Command::SOURCE_HMI; +} // namespace + +typedef std::shared_ptr<BCSetAppPropertiesRequest> BCSetAppPropertiesRequestPtr; + +class BCSetAppPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + BCSetAppPropertiesRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppId)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillByDefault(Return(true)); + } + + MessageSharedPtr CreateMessageWithCustomProperties( + const smart_objects::SmartObject& properties) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params][strings::app_id] = kAppId; + (*msg)[strings::msg_params][strings::properties] = properties; + return msg; + } + + MockAppPtr mock_app_; +}; + +TEST_F(BCSetAppPropertiesRequestTest, + Run_NoAppPropertyChanges_AppIsSame_FailToUpdateAppList) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::NO_CHANGES; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(_, _)) + .Times(0); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)) + .Times(0); + EXPECT_CALL(app_mngr_, CreatePendingApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, SendUpdateAppList()).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppAuthTokenChanged_AppIsSame_NoUpdateAppList) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::auth_token] = kToken; + properties[strings::policy_app_id] = kPolicyAppId; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::AUTH_TOKEN_CHANGED; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, SendUpdateAppList()).Times(0); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_NoAppPropetiesChanged_AppIsNewAndEnabled_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = true; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::NO_CHANGES; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(true)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppEnabledFlagChanged_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = true; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::ENABLED_FLAG_SWITCH; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(BCSetAppPropertiesRequestTest, + Run_AppEnabledFlagChangedToFalse_AppRemoveFromList_AppListUpdated) { + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = kPolicyAppId; + properties[strings::enabled] = false; + + MessageSharedPtr msg = CreateMessageWithCustomProperties(properties); + auto command = CreateCommand<BCSetAppPropertiesRequest>(msg); + + const auto change_status = + policy::PolicyHandler::AppPropertiesState::ENABLED_FLAG_SWITCH; + ON_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)) + .WillByDefault(Return(change_status)); + ON_CALL(mock_policy_handler_, IsNewApplication(kPolicyAppId)) + .WillByDefault(Return(false)); + + MessageSharedPtr notification = CreateMessage(); + ON_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)) + .WillByDefault(Return(notification)); + + EXPECT_CALL(mock_message_helper_, + CreateOnAppPropertiesChangeNotification(kPolicyAppId, _)); + EXPECT_CALL(mock_policy_handler_, + GetAppPropertiesStatus(properties, kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, OnSetAppProperties(properties)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_SetAppProperties), + kSource)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(notification, kSource)); + EXPECT_CALL(app_mngr_, CreatePendingApplication(kPolicyAppId)).Times(0); + EXPECT_CALL(app_mngr_, RemovePendingApplication(kPolicyAppId)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_set_app_properties_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_response_test.cc new file mode 100644 index 0000000000..d4b7447d0d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/bc_set_app_properties_response_test.cc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the names of the copyright holders 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 "gtest/gtest.h" + +#include "hmi/bc_set_app_properties_response.h" + +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace bc_set_app_properties_response { + +using sdl_rpc_plugin::commands::BCSetAppPropertiesResponse; + +class BCSetAppPropertiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BCSetAppPropertiesResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<BCSetAppPropertiesResponse> command( + CreateCommand<BCSetAppPropertiesResponse>(msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace bc_set_app_properties_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_app_properties_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_app_properties_change_notification_test.cc new file mode 100644 index 0000000000..0ab0bc5a35 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_app_properties_change_notification_test.cc @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <stdint.h> + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/smart_object_keys.h" +#include "gtest/gtest.h" +#include "hmi/on_app_properties_change_notification.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_app_properties_change_notification { + +using namespace application_manager; +using sdl_rpc_plugin::commands::OnAppPropertiesChangeNotification; + +typedef std::shared_ptr<OnAppPropertiesChangeNotification> NotificationPtr; +typedef hmi_apis::Common_ServiceType::eType ServiceType; +typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent; + +namespace { +const uint32_t kConnectionKey = 1232u; +const uint32_t kHmiAppId = 321u; +} // namespace + +class OnAppPropertiesChangeNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnAppPropertiesChangeNotificationTest() + : message_(CreateMessage(smart_objects::SmartType_Map)) {} + + protected: + MessageSharedPtr message_; + NotificationPtr command_; +}; + +TEST_F(OnAppPropertiesChangeNotificationTest, SendNotificationToHMI) { + (*message_)[strings::msg_params][strings::app_id] = kConnectionKey; + command_ = CreateCommand<OnAppPropertiesChangeNotification>(message_); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(message_)).Times(1); + + auto mock_app = std::make_shared<NiceMock<MockApplication> >(); + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +} // namespace on_app_properties_change_notification +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc index 6a60cc968e..75da07bc22 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc @@ -79,6 +79,12 @@ void VIGetVehicleDataResponse::Run() { } else { event.set_smart_object(*message_); policy_handler_.OnVehicleDataUpdated(*message_); + if ((*message_).keyExists(strings::msg_params) && + (*message_)[strings::msg_params].keyExists(strings::vin)) { + const std::string vin = + (*message_)[strings::msg_params][strings::vin].asString(); + application_manager_.SetVINCode(vin); + } } event.raise(application_manager_.event_dispatcher()); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 32a00033a1..573d3e58a7 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -66,6 +66,7 @@ #include <time.h> #include <boost/filesystem.hpp> #include "application_manager/application_impl.h" +#include "encryption/hashing.h" #include "interfaces/HMI_API_schema.h" #include "media_manager/media_manager.h" #include "policy/usage_statistics/counter.h" @@ -102,7 +103,9 @@ DeviceTypes devicesType = { std::make_pair(std::string("CARPLAY_WIRELESS_IOS"), hmi_apis::Common_TransportType::WIFI), std::make_pair(std::string("CLOUD_WEBSOCKET"), - hmi_apis::Common_TransportType::CLOUD_WEBSOCKET)}; + hmi_apis::Common_TransportType::CLOUD_WEBSOCKET), + std::make_pair(std::string("WEBENGINE_WEBSOCKET"), + hmi_apis::Common_TransportType::WEBENGINE_WEBSOCKET)}; } /** @@ -946,20 +949,9 @@ void ApplicationManagerImpl::DisconnectCloudApp(ApplicationSharedPtr app) { LOG4CXX_TRACE(logger_, "Cloud app support is disabled. Exiting function"); return; #else - std::string endpoint; - std::string certificate; - std::string auth_token; - std::string cloud_transport_type; - std::string hybrid_app_preference; - bool enabled = true; std::string policy_app_id = app->policy_app_id(); - GetPolicyHandler().GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + policy::AppProperties app_properties; + GetPolicyHandler().GetAppProperties(policy_app_id, app_properties); if (app->IsRegistered() && app->is_cloud_app()) { LOG4CXX_DEBUG(logger_, "Disabled app is registered, unregistering now"); GetRPCService().ManageMobileCommand( @@ -974,12 +966,12 @@ void ApplicationManagerImpl::DisconnectCloudApp(ApplicationSharedPtr app) { connection_handler().RemoveCloudAppDevice(app->device()); transport_manager::transport_adapter::CloudAppProperties properties{ - endpoint, - certificate, - enabled, - auth_token, - cloud_transport_type, - hybrid_app_preference}; + app_properties.endpoint, + app_properties.certificate, + app_properties.enabled, + app_properties.auth_token, + app_properties.transport_type, + app_properties.hybrid_app_preference}; // Create device in pending state LOG4CXX_DEBUG(logger_, "Re-adding the cloud app device"); connection_handler().AddCloudAppDevice(policy_app_id, properties); @@ -999,12 +991,6 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() { GetPolicyHandler().GetEnabledCloudApps(enabled_apps); std::vector<std::string>::iterator enabled_it = enabled_apps.begin(); std::vector<std::string>::iterator enabled_end = enabled_apps.end(); - std::string endpoint; - std::string certificate; - std::string auth_token; - std::string cloud_transport_type; - std::string hybrid_app_preference_str; - bool enabled = true; // Store old device map and clear the current map pending_device_map_lock_ptr_->Acquire(); @@ -1012,20 +998,20 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() { std::map<std::string, std::string> old_device_map = pending_device_map_; pending_device_map_ = std::map<std::string, std::string>(); // Create a device for each newly enabled cloud app + policy::AppProperties app_properties; for (; enabled_it != enabled_end; ++enabled_it) { - GetPolicyHandler().GetCloudAppParameters(*enabled_it, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference_str); + GetPolicyHandler().GetAppProperties(*enabled_it, app_properties); + + if (app_properties.endpoint.empty()) { + continue; + } mobile_apis::HybridAppPreference::eType hybrid_app_preference = mobile_apis::HybridAppPreference::INVALID_ENUM; smart_objects::EnumConversionHelper< mobile_apis::HybridAppPreference::eType>:: - StringToEnum(hybrid_app_preference_str, &hybrid_app_preference); + StringToEnum(app_properties.hybrid_app_preference, + &hybrid_app_preference); auto policy_id = *enabled_it; policy::StringArray nicknames; @@ -1057,22 +1043,22 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() { } } - pending_device_map_.insert( - std::pair<std::string, std::string>(endpoint, policy_id)); + pending_device_map_.insert(std::pair<std::string, std::string>( + app_properties.endpoint, policy_id)); // Determine which endpoints were disabled by erasing all enabled apps from // the old device list - auto old_device_it = old_device_map.find(endpoint); + auto old_device_it = old_device_map.find(app_properties.endpoint); if (old_device_it != old_device_map.end()) { old_device_map.erase(old_device_it); } transport_manager::transport_adapter::CloudAppProperties properties{ - endpoint, - certificate, - enabled, - auth_token, - cloud_transport_type, - hybrid_app_preference_str}; + app_properties.endpoint, + app_properties.certificate, + app_properties.enabled, + app_properties.auth_token, + app_properties.transport_type, + app_properties.hybrid_app_preference}; // If the device was disconnected, this will reinitialize the device connection_handler().AddCloudAppDevice(policy_id, properties); @@ -1094,7 +1080,7 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() { const std::string app_icon_dir(settings_.app_icons_folder()); const std::string full_icon_path(app_icon_dir + "/" + policy_id); if (!file_system::FileExists(full_icon_path)) { - AppIconInfo icon_info(endpoint, false); + AppIconInfo icon_info(app_properties.endpoint, false); LOG4CXX_DEBUG( logger_, "Inserting cloud app into icon map: " << app_icon_map_.size()); @@ -1158,12 +1144,6 @@ void ApplicationManagerImpl::CreatePendingApplication( connection_handler::DeviceHandle device_id) { LOG4CXX_AUTO_TRACE(logger_); - std::string endpoint; - std::string certificate; - std::string auth_token; - std::string cloud_transport_type; - std::string hybrid_app_preference_str; - bool enabled = true; std::string name = device_info.name(); pending_device_map_lock_ptr_->Acquire(); auto it = pending_device_map_.find(name); @@ -1207,34 +1187,29 @@ void ApplicationManagerImpl::CreatePendingApplication( if (file_system::FileExists(full_icon_path)) { application->set_app_icon_path(full_icon_path); } - - GetPolicyHandler().GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference_str); + policy::AppProperties app_properties; + GetPolicyHandler().GetAppProperties(policy_app_id, app_properties); mobile_apis::HybridAppPreference::eType hybrid_app_preference_enum; - bool convert_result = smart_objects::EnumConversionHelper< + const bool convert_result = smart_objects::EnumConversionHelper< mobile_apis::HybridAppPreference::eType>:: - StringToEnum(hybrid_app_preference_str, &hybrid_app_preference_enum); + StringToEnum(app_properties.hybrid_app_preference, + &hybrid_app_preference_enum); - if (!hybrid_app_preference_str.empty() && !convert_result) { - LOG4CXX_ERROR( - logger_, - "Could not convert string to enum: " << hybrid_app_preference_str); + if (!app_properties.hybrid_app_preference.empty() && !convert_result) { + LOG4CXX_ERROR(logger_, + "Could not convert string to enum: " + << app_properties.hybrid_app_preference); return; } application->set_hmi_application_id(GenerateNewHMIAppID()); - application->set_cloud_app_endpoint(endpoint); - application->set_auth_token(auth_token); - application->set_cloud_app_transport_type(cloud_transport_type); + application->set_cloud_app_endpoint(app_properties.endpoint); + application->set_auth_token(app_properties.auth_token); + application->set_cloud_app_transport_type(app_properties.transport_type); application->set_hybrid_app_preference(hybrid_app_preference_enum); - application->set_cloud_app_certificate(certificate); + application->set_cloud_app_certificate(app_properties.certificate); sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); LOG4CXX_DEBUG(logger_, @@ -1246,6 +1221,106 @@ void ApplicationManagerImpl::CreatePendingApplication( SendUpdateAppList(); } +void ApplicationManagerImpl::RemovePendingApplication( + const std::string& policy_app_id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); + PolicyAppIdPredicate finder(policy_app_id); + auto app_it = + std::find_if(apps_to_register_.begin(), apps_to_register_.end(), finder); + + if (apps_to_register_.end() == app_it) { + LOG4CXX_WARN( + logger_, + "Unable to find app to remove (" << policy_app_id << "), skipping"); + return; + } + + apps_to_register_.erase(app_it); + LOG4CXX_DEBUG(logger_, + "Remove " << policy_app_id + << " from apps_to_register_. new size = " + << apps_to_register_.size()); +} + +void ApplicationManagerImpl::CreatePendingApplication( + const std::string& policy_app_id) { + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + GetPolicyHandler().GetInitialAppData( + policy_app_id, &nicknames, &app_hmi_types); + + if (nicknames.empty()) { + LOG4CXX_ERROR(logger_, + "Cloud/Web App " << policy_app_id << "missing nickname"); + return; + } + + const std::string display_name = nicknames[0]; + + const auto web_engine_device = connection_handler_->GetWebEngineDeviceInfo(); + + ApplicationSharedPtr application( + new ApplicationImpl(0, + policy_app_id, + web_engine_device.mac_address(), + web_engine_device.device_handle(), + custom_str::CustomString(display_name), + GetPolicyHandler().GetStatisticManager(), + *this)); + + 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); + } + policy::AppProperties app_properties; + GetPolicyHandler().GetAppProperties(policy_app_id, app_properties); + + mobile_apis::HybridAppPreference::eType hybrid_app_preference_enum; + const bool convert_result = smart_objects::EnumConversionHelper< + mobile_apis::HybridAppPreference::eType>:: + StringToEnum(app_properties.hybrid_app_preference, + &hybrid_app_preference_enum); + + if (!app_properties.hybrid_app_preference.empty() && !convert_result) { + LOG4CXX_ERROR(logger_, + "Could not convert string to enum: " + << app_properties.hybrid_app_preference); + return; + } + + application->set_hmi_application_id(GenerateNewHMIAppID()); + application->set_cloud_app_endpoint(app_properties.endpoint); + application->set_auth_token(app_properties.auth_token); + application->set_cloud_app_transport_type(app_properties.transport_type); + application->set_hybrid_app_preference(hybrid_app_preference_enum); + application->set_cloud_app_certificate(app_properties.certificate); + + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); + apps_to_register_.insert(application); + LOG4CXX_DEBUG(logger_, + "Insert " << application->name().c_str() + << " to apps_to_register_. new size = " + << apps_to_register_.size()); +} + +void ApplicationManagerImpl::OnWebEngineDeviceCreated() { + LOG4CXX_AUTO_TRACE(logger_); + const auto enabled_local_apps = policy_handler_->GetEnabledLocalApps(); + + if (enabled_local_apps.empty()) { + LOG4CXX_DEBUG(logger_, "No enabled local apps present"); + return; + } + + for (auto policy_app_id : enabled_local_apps) { + CreatePendingApplication(policy_app_id); + } + SendUpdateAppList(); +} + void ApplicationManagerImpl::SetPendingApplicationState( const transport_manager::ConnectionUID connection_id, const transport_manager::DeviceInfo& device_info) { @@ -3141,6 +3216,15 @@ void ApplicationManagerImpl::UnregisterApplication( RemoveAppsWaitingForRegistration(handle); } } + + const auto enabled_local_apps = policy_handler_->GetEnabledLocalApps(); + if (helpers::in_range(enabled_local_apps, app_to_remove->policy_app_id())) { + LOG4CXX_DEBUG(logger_, + "Enabled local app has been unregistered. Re-create " + "pending application"); + CreatePendingApplication(app_to_remove->policy_app_id()); + } + RefreshCloudAppInformation(); SendUpdateAppList(); } @@ -4294,6 +4378,11 @@ void ApplicationManagerImpl::ApplyFunctorForEachPlugin( plugin_manager_->ForEachPlugin(functor); } +void ApplicationManagerImpl::SetVINCode(const std::string& vin_code) { + LOG4CXX_AUTO_TRACE(logger_); + connection_handler_->CreateWebEngineDevice(vin_code); +} + event_engine::EventDispatcher& ApplicationManagerImpl::event_dispatcher() { return event_dispatcher_; } 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 48cf1460f9..4a64fdb128 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -1817,8 +1817,10 @@ bool MessageHelper::CreateHMIApplicationStruct( &secondary_device_info); } - message[strings::is_cloud_application] = app->is_cloud_app(); - if (app->is_cloud_app()) { + const bool is_cloud_app = app->is_cloud_app(); + message[strings::is_cloud_application] = is_cloud_app; + + if (is_cloud_app) { message[strings::cloud_connection_status] = app_mngr.GetCloudAppConnectionStatus(app); } @@ -1903,6 +1905,57 @@ void MessageHelper::SendOnAppUnregNotificationToHMI( app_mngr.GetRPCService().ManageHMICommand(notification); } +smart_objects::SmartObjectSPtr +MessageHelper::CreateOnAppPropertiesChangeNotification( + const std::string& policy_app_id, ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + + smart_objects::SmartObject& message = *notification; + message[strings::params][strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_OnAppPropertiesChange; + message[strings::params][strings::message_type] = MessageType::kNotification; + + policy::AppProperties app_properties; + app_mngr.GetPolicyHandler().GetAppProperties(policy_app_id, app_properties); + + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + app_mngr.GetPolicyHandler().GetInitialAppData( + policy_app_id, &nicknames, &app_hmi_types); + + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + properties[strings::policy_app_id] = policy_app_id; + properties[strings::enabled] = app_properties.enabled; + + smart_objects::SmartObject nicknames_array(smart_objects::SmartType_Array); + size_t i = 0; + for (const auto& nickname : nicknames) { + nicknames_array[i++] = nickname; + } + properties[strings::nicknames] = nicknames_array; + + if (!app_properties.auth_token.empty()) { + properties[strings::auth_token] = app_properties.auth_token; + } + if (!app_properties.transport_type.empty()) { + properties[strings::transport_type] = app_properties.transport_type; + } + if (!app_properties.hybrid_app_preference.empty()) { + properties[strings::hybrid_app_preference] = + app_properties.hybrid_app_preference; + } + if (!app_properties.endpoint.empty()) { + properties[strings::endpoint] = app_properties.endpoint; + } + + message[strings::msg_params][strings::properties] = properties; + return notification; +} + smart_objects::SmartObjectSPtr MessageHelper::GetBCActivateAppRequestToHMI( ApplicationConstSharedPtr app, const policy::PolicyHandlerInterface& policy_handler, diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 82ae42e88a..38c43b5dcd 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -111,6 +111,7 @@ const uint32_t kConnectionKey = 1232u; const std::string kAppName = "appName"; const WindowID kDefaultWindowId = mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +const std::vector<std::string> kEnabledLocalApps = {"localAppId"}; typedef hmi_apis::Common_ServiceStatusUpdateReason::eType ServiceStatusUpdateReason; @@ -118,6 +119,12 @@ typedef hmi_apis::Common_ServiceType::eType ServiceType; typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent; typedef utils::Optional<ServiceStatusUpdateReason> UpdateReasonOptional; +const std::string kPolicyAppID = "test policy id"; +transport_manager::DeviceInfo kDeviceInfo(1, + "mac", + "name", + "WEB_ENGINE_DEVICE"); + #if defined(CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT) // Cloud application params const std::string kEndpoint = "endpoint"; @@ -129,6 +136,12 @@ const mobile_api::HybridAppPreference::eType kHybridAppPreference = mobile_api::HybridAppPreference::CLOUD; const std::string kHybridAppPreferenceStr = "CLOUD"; const bool kEnabled = true; +const policy::AppProperties app_properties(kEndpoint2, + kCertificate, + kEnabled, + kAuthToken, + kTransportType, + kHybridAppPreferenceStr); #endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT } // namespace @@ -218,6 +231,8 @@ class ApplicationManagerImplTest smart_objects::SmartType_Map))); ON_CALL(*mock_policy_handler_, GetStatisticManager()) .WillByDefault(Return(mock_statistics_manager_)); + ON_CALL(*mock_policy_handler_, GetEnabledLocalApps()) + .WillByDefault(Return(kEnabledLocalApps)); } void CreateAppManager() { @@ -307,6 +322,9 @@ class ApplicationManagerImplTest void AddCloudAppToPendingDeviceMap(); void CreatePendingApplication(); #endif + + void CreatePendingApplication(const std::string& policy_app_id); + uint32_t app_id_; NiceMock<policy_test::MockPolicySettings> mock_policy_settings_; std::shared_ptr<NiceMock<resumption_test::MockResumptionData> > mock_storage_; @@ -1245,7 +1263,9 @@ TEST_F(ApplicationManagerImplTest, UnregisterAnotherAppDuringAudioPassThru) { EXPECT_CALL(*mock_app_2, device()).WillRepeatedly(Return(0)); EXPECT_CALL(*mock_app_2, mac_address()) .WillRepeatedly(ReturnRef(dummy_mac_address)); - EXPECT_CALL(*mock_app_2, policy_app_id()).WillRepeatedly(Return("")); + const std::string app2_policy_id = "app2_policy_id"; + EXPECT_CALL(*mock_app_2, policy_app_id()) + .WillRepeatedly(Return(app2_policy_id)); EXPECT_CALL(*mock_app_2, protocol_version()) .WillRepeatedly( Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); @@ -1282,6 +1302,9 @@ TEST_F(ApplicationManagerImplTest, UnregisterAnotherAppDuringAudioPassThru) { audio_type); } + std::vector<std::string> enabled_apps = {app2_policy_id}; + EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(1); + // while running APT, app 1 is unregistered app_manager_impl_->UnregisterApplication( app_id_1, mobile_apis::Result::SUCCESS, false, true); @@ -1664,14 +1687,8 @@ void ApplicationManagerImplTest::AddCloudAppToPendingDeviceMap() { std::vector<std::string> enabled_apps{"1234"}; EXPECT_CALL(*mock_policy_handler_, GetEnabledCloudApps(_)) .WillOnce(SetArgReferee<0>(enabled_apps)); - EXPECT_CALL(*mock_policy_handler_, GetCloudAppParameters(_, _, _, _, _, _, _)) - .WillOnce(DoAll(SetArgReferee<1>(kEnabled), - SetArgReferee<2>(kEndpoint2), - SetArgReferee<3>(kCertificate), - SetArgReferee<4>(kAuthToken), - SetArgReferee<5>(kTransportType), - SetArgReferee<6>(kHybridAppPreferenceStr), - Return(true))); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); std::vector<std::string> nicknames{"CloudApp"}; EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(_, _, _)) @@ -1696,14 +1713,8 @@ void ApplicationManagerImplTest::CreatePendingApplication() { EXPECT_CALL(*mock_policy_handler_, GetStatisticManager()) .WillOnce(Return(std::shared_ptr<usage_statistics::StatisticsManager>( new usage_statistics_test::MockStatisticsManager()))); - EXPECT_CALL(*mock_policy_handler_, GetCloudAppParameters(_, _, _, _, _, _, _)) - .WillOnce(DoAll(SetArgReferee<1>(kEnabled), - SetArgReferee<2>(kEndpoint2), - SetArgReferee<3>(kCertificate), - SetArgReferee<4>(kAuthToken), - SetArgReferee<5>(kTransportType), - SetArgReferee<6>(kHybridAppPreferenceStr), - Return(true))); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); // Expect Update app list EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(1); app_manager_impl_->CreatePendingApplication(1, device_info, 1); @@ -1733,14 +1744,8 @@ TEST_F(ApplicationManagerImplTest, SetPendingState) { EXPECT_CALL(*mock_policy_handler_, GetEnabledCloudApps(_)) .WillOnce(SetArgReferee<0>(enabled_apps)); - EXPECT_CALL(*mock_policy_handler_, GetCloudAppParameters(_, _, _, _, _, _, _)) - .WillOnce(DoAll(SetArgReferee<1>(kEnabled), - SetArgReferee<2>(kEndpoint2), - SetArgReferee<3>(kCertificate), - SetArgReferee<4>(kAuthToken), - SetArgReferee<5>(kTransportType), - SetArgReferee<6>(kHybridAppPreferenceStr), - Return(true))); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); std::vector<std::string> nicknames{"CloudApp"}; EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(_, _, _)) @@ -1883,14 +1888,8 @@ TEST_F(ApplicationManagerImplTest, PolicyIDByIconUrl_Success) { std::vector<std::string> enabled_apps{"1234"}; EXPECT_CALL(*mock_policy_handler_, GetEnabledCloudApps(_)) .WillOnce(SetArgReferee<0>(enabled_apps)); - EXPECT_CALL(*mock_policy_handler_, GetCloudAppParameters(_, _, _, _, _, _, _)) - .WillOnce(DoAll(SetArgReferee<1>(kEnabled), - SetArgReferee<2>(kEndpoint2), - SetArgReferee<3>(kCertificate), - SetArgReferee<4>(kAuthToken), - SetArgReferee<5>(kTransportType), - SetArgReferee<6>(kHybridAppPreferenceStr), - Return(true))); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); std::vector<std::string> nicknames{"CloudApp"}; EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(_, _, _)) @@ -1932,8 +1931,105 @@ TEST_F(ApplicationManagerImplTest, SetIconFileFromSystemRequest_Success) { app_manager_impl_->SetIconFileFromSystemRequest("1234"); EXPECT_TRUE(file_system::RemoveDirectory(kDirectoryName, true)); } - #endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT + +void ApplicationManagerImplTest::CreatePendingApplication( + const std::string& policy_app_id) { + // CreatePendingApplication + std::vector<std::string> nicknames{"PendingApplication"}; + EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(policy_app_id, _, _)) + .WillOnce(DoAll(SetArgPointee<1>(nicknames), Return(true))); + EXPECT_CALL(mock_connection_handler_, GetWebEngineDeviceInfo()) + .WillOnce(ReturnRef(kDeviceInfo)); + EXPECT_CALL(*mock_policy_handler_, GetStatisticManager()) + .WillOnce(Return(std::shared_ptr<usage_statistics::StatisticsManager>( + new usage_statistics_test::MockStatisticsManager()))); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); + // Expect NO Update app list + EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(0); + app_manager_impl_->CreatePendingApplication(policy_app_id); + AppsWaitRegistrationSet app_list = + app_manager_impl_->AppsWaitingForRegistration().GetData(); + EXPECT_EQ(1u, app_list.size()); +} + +TEST_F(ApplicationManagerImplTest, CreatePendingApplicationByPolicyAppID) { + CreatePendingApplication(kPolicyAppID); +} + +TEST_F(ApplicationManagerImplTest, RemoveExistingPendingApplication_SUCCESS) { + CreatePendingApplication(kPolicyAppID); + auto app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + ASSERT_EQ(1u, app_list.size()); + + app_manager_impl_->RemovePendingApplication(kPolicyAppID); + app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + EXPECT_TRUE(app_list.empty()); +} + +TEST_F(ApplicationManagerImplTest, + RemovePendingApplicationFromEmptyList_NoAppRemoved_SUCCESS) { + auto app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + ASSERT_TRUE(app_list.empty()); + + app_manager_impl_->RemovePendingApplication(kPolicyAppID); + app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + EXPECT_TRUE(app_list.empty()); +} + +TEST_F( + ApplicationManagerImplTest, + OnWebEngineDeviceCreated_NoEnabledLocalApps_PendingApplicationNotCreatedAndNoUpdateAppList) { + std::vector<std::string> enabled_apps; + EXPECT_CALL(*mock_policy_handler_, GetEnabledLocalApps()) + .WillOnce(Return(enabled_apps)); + EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(0); + + app_manager_impl_->OnWebEngineDeviceCreated(); + + auto app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + EXPECT_TRUE(app_list.empty()); +} + +TEST_F( + ApplicationManagerImplTest, + OnWebEngineDeviceCreated_PendingApplicationCreatedAndUpdateAppListSentToHMI) { + std::vector<std::string> enabled_apps = {"app1"}; + std::vector<std::string> nicknames{"PendingApplication"}; + + EXPECT_CALL(*mock_policy_handler_, GetEnabledLocalApps()) + .WillOnce(Return(enabled_apps)); + EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(_, _)).Times(1); + EXPECT_CALL(*mock_policy_handler_, GetAppProperties(_, _)) + .WillOnce(DoAll(SetArgReferee<1>(app_properties), Return(true))); + EXPECT_CALL(*mock_policy_handler_, GetInitialAppData(_, _, _)) + .WillOnce(DoAll(SetArgPointee<1>(nicknames), Return(true))); + EXPECT_CALL(mock_connection_handler_, GetWebEngineDeviceInfo()) + .WillOnce(ReturnRef(kDeviceInfo)); + + app_manager_impl_->OnWebEngineDeviceCreated(); + + auto app_list = app_manager_impl_->AppsWaitingForRegistration().GetData(); + EXPECT_EQ(1u, app_list.size()); +} + +TEST_F(ApplicationManagerImplTest, AddAndRemoveQueryAppDevice_SUCCESS) { + const connection_handler::DeviceHandle device_handle = 1u; + ASSERT_FALSE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); + + app_manager_impl_->OnQueryAppsRequest(device_handle); + EXPECT_TRUE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); + app_manager_impl_->RemoveDevice(device_handle); + EXPECT_FALSE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); +} + +TEST_F(ApplicationManagerImplTest, SetVINCode_SUCCESS) { + const std::string vin_code = "VIN CODE"; + EXPECT_CALL(mock_connection_handler_, CreateWebEngineDevice(vin_code)); + app_manager_impl_->SetVINCode(vin_code); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/include/application_manager/commands/commands_test.h b/src/components/application_manager/test/include/application_manager/commands/commands_test.h index a047de81b9..fdaef2c716 100644 --- a/src/components/application_manager/test/include/application_manager/commands/commands_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/commands_test.h @@ -245,6 +245,21 @@ MATCHER_P(HMIResultCodeIs, result_code, "") { .asInt()); } +MATCHER_P3( + HMIMessageParametersAre, correlation_id, function_id, result_code, "") { + using namespace application_manager; + + const bool corr_ids_eq = + correlation_id == + (*arg)[strings::params][strings::correlation_id].asInt(); + const bool func_ids_eq = + (*arg)[strings::params][strings::function_id].asInt() == function_id; + const bool res_codes_eq = + (*arg)[strings::params][hmi_response::code].asInt() == result_code; + + return corr_ids_eq && func_ids_eq && res_codes_eq; +} + MATCHER_P3(MobileResponseIs, result_code, result_info, result_success, "") { mobile_apis::Result::eType code = static_cast<mobile_apis::Result::eType>( (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 072199082e..eb3c97bfff 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -269,6 +269,9 @@ class MockMessageHelper { void(ApplicationConstSharedPtr app, const bool is_unexpected_disconnect, ApplicationManager& app_mngr)); + MOCK_METHOD2(CreateOnAppPropertiesChangeNotification, + smart_objects::SmartObjectSPtr(const std::string& policy_app_id, + ApplicationManager& app_mngr)); MOCK_METHOD4(SendLaunchApp, void(const uint32_t connection_key, const std::string& urlSchema, diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 628fd97ae8..959bbf5bd0 100755..100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -485,6 +485,13 @@ bool MessageHelper::CreateHMIApplicationStruct( app, session_observer, policy_handler, output, app_mngr); } +smart_objects::SmartObjectSPtr +MessageHelper::CreateOnAppPropertiesChangeNotification( + const std::string& policy_app_id, ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock() + ->CreateOnAppPropertiesChangeNotification(policy_app_id, app_mngr); +} + void MessageHelper::SendOnAppUnregNotificationToHMI( ApplicationConstSharedPtr app, const bool is_unexpected_disconnect, diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 04b5049c3d..eb684e8c69 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -166,6 +166,26 @@ class ApplicationManager { virtual DataAccessor<ApplicationSet> applications() const = 0; virtual DataAccessor<AppsWaitRegistrationSet> pending_applications() const = 0; + + /** + * @brief CreatePendingApplication Add applicaiton to pending state + * All info mandatory for application will be fetched from policy database. + * Application will be stored to internal pending applicaitons list. + * UpdateAppList will not be trigerred + * Application will be created if app exists in policy database and + * nicknames are not empty + * @param policy_app_id app id to store + */ + virtual void CreatePendingApplication(const std::string& policy_app_id) = 0; + + /** + * @brief RemovePendingApplication Remove applicaiton from pending state + * Application will be removed from the internal pending applicaitons list. + * UpdateAppList will not be trigerred + * @param policy_app_id app id to remove + */ + virtual void RemovePendingApplication(const std::string& policy_app_id) = 0; + virtual DataAccessor<ReregisterWaitList> reregister_applications() const = 0; virtual ApplicationSharedPtr application(uint32_t app_id) const = 0; @@ -691,6 +711,8 @@ class ApplicationManager { virtual void ApplyFunctorForEachPlugin( std::function<void(plugin_manager::RPCPlugin&)> functor) = 0; + virtual void SetVINCode(const std::string& vin_code) = 0; + /* * @brief Converts connection string transport type representation * to HMI Common_TransportType diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index e5706c2003..4b155f12cc 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -82,6 +82,10 @@ class MockApplicationManager : public application_manager::ApplicationManager { DataAccessor<application_manager::AppsWaitRegistrationSet>()); MOCK_CONST_METHOD0(reregister_applications, DataAccessor<application_manager::ReregisterWaitList>()); + MOCK_METHOD1(CreatePendingApplication, + void(const std::string& policy_app_id)); + MOCK_METHOD1(RemovePendingApplication, + void(const std::string& policy_app_id)); MOCK_CONST_METHOD1( application, application_manager::ApplicationSharedPtr(uint32_t app_id)); MOCK_CONST_METHOD0(active_application, @@ -283,6 +287,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { ApplyFunctorForEachPlugin, void(std::function<void(application_manager::plugin_manager::RPCPlugin&)> functor)); + MOCK_METHOD1(SetVINCode, void(const std::string& vin_code)); + MOCK_CONST_METHOD0(GetVINCode, const std::string()); MOCK_METHOD1( GetDeviceTransportType, hmi_apis::Common_TransportType::eType(const std::string& transport_type)); |