diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin')
18 files changed, 1779 insertions, 24 deletions
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 |