From 4eaa00242435d7afa4c0ba5cff056a99f74153e1 Mon Sep 17 00:00:00 2001 From: Konstantin Kolodiy Date: Fri, 4 Apr 2014 17:00:15 +0400 Subject: [PATCH] APPLINK-6400: - Implemente counters: count_of_sync_reboots, count_of_user_selections count_of_run_attempts_while_revoked, count_of_rejected_rpc_calls, count_of_rpcs_sent_in_hmi_none, count_of_rejections_nickname_mismatch, count_of_rejections_duplicate_name, count_of_rejections_sync_out_of_memory Signed-off-by: Justin Dickow Conflicts: src/components/application_manager/src/application_impl.cc src/components/application_manager/src/application_manager_impl.cc --- .../include/application_manager/application.h | 8 + .../include/application_manager/application_impl.h | 6 +- .../include/application_manager/usage_statistics.h | 27 +- .../application_manager/src/application_impl.cc | 20 +- .../src/application_manager_impl.cc | 338 ++++++++++++--------- .../mobile/register_app_interface_request.cc | 11 +- .../src/policies/policy_handler.cc | 13 + .../application_manager/src/usage_statistics.cc | 50 +-- 8 files changed, 282 insertions(+), 191 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index be9e702..f21f786 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -53,6 +53,8 @@ namespace mobile_api = mobile_apis; namespace smart_objects = NsSmartDeviceLink::NsSmartObjects; typedef int32_t ErrorCode; +class UsageStatistics; + enum APIVersion { kUnknownAPI = -1, kAPIV0 = 0, @@ -439,6 +441,12 @@ class Application : public virtual InitialApplicationData, virtual bool SubscribeToIVI(uint32_t vehicle_info_type_) = 0; virtual bool IsSubscribedToIVI(uint32_t vehicle_info_type_) = 0; virtual bool UnsubscribeFromIVI(uint32_t vehicle_info_type_) = 0; + + /** + * Returns object for recording statistics + * @return object for recording statistics + */ + virtual UsageStatistics& usage_report() = 0; }; typedef utils::SharedPtr ApplicationSharedPtr; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 0e6326b..82bf5fe 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -36,6 +36,7 @@ #include #include #include + #include "application_manager/application_data_impl.h" #include "application_manager/usage_statistics.h" #include "connection_handler/device.h" @@ -135,7 +136,8 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, */ virtual uint32_t UpdateHash(); - ApplicationUsageReport& usage_report(); + UsageStatistics& usage_report(); + protected: void CleanupFiles(); @@ -169,7 +171,7 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, AppFilesMap app_files_; std::set subscribed_buttons_; std::set subscribed_vehicle_info_; - ApplicationUsageReport usage_report_; + UsageStatistics usage_report_; DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); }; diff --git a/src/components/application_manager/include/application_manager/usage_statistics.h b/src/components/application_manager/include/application_manager/usage_statistics.h index 66cdb1a..0d3571c 100644 --- a/src/components/application_manager/include/application_manager/usage_statistics.h +++ b/src/components/application_manager/include/application_manager/usage_statistics.h @@ -30,17 +30,19 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "usage_statistics/counter.h" -#include "smart_objects/smart_object.h" +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_USAGE_STATISTICS_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_USAGE_STATISTICS_H_ +#include +#include "usage_statistics/counter.h" #include "interfaces/MOBILE_API.h" namespace application_manager { -class ApplicationUsageReport { +class UsageStatistics { public: - ApplicationUsageReport(const std::string& app_id, - usage_statistics::StatisticsManager* statistics_manager); + UsageStatistics(const std::string& app_id, + usage_statistics::StatisticsManager* statistics_manager); void RecordHmiStateChanged(mobile_apis::HMILevel::eType new_hmi_level); void RecordAppRegistrationGuiLanguage( mobile_apis::Language::eType gui_language); @@ -48,12 +50,19 @@ class ApplicationUsageReport { mobile_apis::Language::eType vui_language); void RecordRpcSentInHMINone(); void RecordPolicyRejectedRpcCall(); + void RecordAppUserSelection(); + void RecordRunAttemptsWhileRevoked(); + private: usage_statistics::AppStopwatch time_in_hmi_state_; - usage_statistics::AppInfo app_registration_language_gui_; - usage_statistics::AppInfo app_registration_language_vui_; - usage_statistics::AppCounter count_of_rejected_rpc_calls_; - usage_statistics::AppCounter count_of_rpcs_sent_in_hmi_none_; + usage_statistics::AppInfo app_registration_language_gui_; + usage_statistics::AppInfo app_registration_language_vui_; + usage_statistics::AppCounter count_of_rejected_rpc_calls_; + usage_statistics::AppCounter count_of_rpcs_sent_in_hmi_none_; + usage_statistics::AppCounter count_of_user_selections_; + usage_statistics::AppCounter count_of_run_attempts_while_revoked_; }; } // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_USAGE_STATISTICS_H_ diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index bf84482..1a1b5c3 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -44,7 +44,10 @@ log4cxx::LoggerPtr g_logger = log4cxx::Logger::getLogger("ApplicationManager"); namespace application_manager { -ApplicationImpl::ApplicationImpl(uint32_t application_id) +ApplicationImpl::ApplicationImpl( + uint32_t application_id, + const std::string& global_app_id, + usage_statistics::StatisticsManager* statistics_manager) : app_id_(application_id), active_message_(NULL), is_media_(false), @@ -60,7 +63,7 @@ ApplicationImpl::ApplicationImpl(uint32_t application_id) has_been_activated_(false), tts_speak_state_(false), device_(0), - grammar_id_(0) { + usage_report_(global_app_id, statistics_manager) { } ApplicationImpl::~ApplicationImpl() { @@ -194,6 +197,7 @@ void ApplicationImpl::set_hmi_level( } hmi_level_ = hmi_level; + usage_report_.RecordHmiStateChanged(hmi_level); } void ApplicationImpl::set_hmi_supports_navi_streaming(const bool& supports) { @@ -249,14 +253,6 @@ void ApplicationImpl::set_device(connection_handler::DeviceHandle device) { device_ = device; } -uint32_t ApplicationImpl::get_grammar_id() { - return grammar_id_; -} - -void ApplicationImpl::set_grammar_id(uint32_t value) { - grammar_id_ = value; -} - bool ApplicationImpl::has_been_activated() const { return has_been_activated_; } @@ -331,6 +327,10 @@ bool ApplicationImpl::UnsubscribeFromIVI(uint32_t vehicle_info_type_) { return (subscribed_vehicle_info_.size() == old_size - 1); } +UsageStatistics& ApplicationImpl::usage_report() { + return usage_report_; +} + const std::set& ApplicationImpl::SubscribedButtons() const { return subscribed_buttons_; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index dd87862..37f0e7b 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -42,6 +42,7 @@ #include "application_manager/commands/command_notification_impl.h" #include "application_manager/message_helper.h" #include "application_manager/mobile_message_handler.h" +#include "application_manager/policies/policy_handler.h" #include "connection_handler/connection_handler_impl.h" #include "formatters/formatter_json_rpc.h" #include "formatters/CFormatterJsonSDLRPCv2.hpp" @@ -49,8 +50,8 @@ #include "config_profile/profile.h" #include "utils/threads/thread.h" #include "utils/file_system.h" -#include "policies/policy_manager.h" #include "application_manager/application_impl.h" +#include "usage_statistics/counter.h" namespace application_manager { @@ -83,18 +84,12 @@ ApplicationManagerImpl::ApplicationManagerImpl() messages_to_hmi_("application_manager::ToHMHThreadImpl", this), request_ctrl_(), hmi_capabilities_(this), - unregister_reason_(mobile_api::AppInterfaceUnregisteredReason::MASTER_RESET), + unregister_reason_(mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF), media_manager_(NULL), - resume_ctrl_(this) -{ + resume_ctrl_(this) { LOG4CXX_INFO(logger_, "Creating ApplicationManager"); - srand(time(NULL)); - if (!policies_manager_.Init()) { - LOG4CXX_ERROR(logger_, "Policies manager initialization failed."); - return; - } - media_manager_ = media_manager::MediaManagerImpl::instance(); + CreatePoliciesManager(); } bool ApplicationManagerImpl::InitThread(threads::Thread* thread) { @@ -119,10 +114,14 @@ bool ApplicationManagerImpl::InitThread(threads::Thread* thread) { ApplicationManagerImpl::~ApplicationManagerImpl() { LOG4CXX_INFO(logger_, "Destructing ApplicationManager."); + if (policy_manager_) { + LOG4CXX_INFO(logger_, "Unloading policy library."); + policy::PolicyHandler::instance()->UnloadPolicyLibrary(); + } + policy_manager_ = NULL; media_manager_ = NULL; hmi_handler_ = NULL; connection_handler_ = NULL; - policy_manager_ = NULL; hmi_so_factory_ = NULL; mobile_so_factory_ = NULL; protocol_handler_ = NULL; @@ -133,8 +132,7 @@ bool ApplicationManagerImpl::Stop() { LOG4CXX_INFO(logger_, "Stop ApplicationManager."); try { UnregisterAllApplications(); - } - catch(...) { + } catch (...) { LOG4CXX_ERROR(logger_, "An error occured during unregistering applications."); } @@ -146,7 +144,7 @@ ApplicationSharedPtr ApplicationManagerImpl::application(int32_t app_id) const { sync_primitives::AutoLock lock(applications_list_lock_); std::map::const_iterator it = - applications_.find(app_id); + applications_.find(app_id); if (applications_.end() != it) { return it->second; } else { @@ -179,13 +177,22 @@ std::vector ApplicationManagerImpl::applications_by_button return result; } -std::vector ApplicationManagerImpl::applications_by_ivi( - uint32_t vehicle_info) { - std::vector result; - for (std::set::iterator it = application_list_.begin(); - application_list_.end() != it; - ++it) { - if ((*it)->IsSubscribedToIVI(vehicle_info)) { +std::vector> ApplicationManagerImpl::IviInfoUpdated( +VehicleDataType vehicle_info, int value) { + // Notify Policy Manager if available about info it's interested in, + // i.e. odometer etc + switch (vehicle_info) { + case ODOMETER: + policy::PolicyHandler::instance()->KmsChanged(value); + break; + default: + break; + } + + std::vector> result; + for (std::set>::iterator it = application_list_.begin(); + application_list_.end() != it; ++it) { + if ((*it)->IsSubscribedToIVI(static_cast(vehicle_info))) { result.push_back(*it); } } @@ -232,7 +239,7 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( if (connection_handler_) { connection_handler::ConnectionHandlerImpl* con_handler_impl = static_cast( - connection_handler_); + connection_handler_); if (con_handler_impl->GetDataOnSessionKey(connection_key, &app_id, &sessions_list, &device_id) == -1) { @@ -248,9 +255,17 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( } } - ApplicationSharedPtr application(new - ApplicationImpl(app_id)); + smart_objects::SmartObject& params = message[strings::msg_params]; + + const std::string mobile_app_id = params[strings::app_id].asString(); + ApplicationSharedPtr application(new ApplicationImpl(app_id, mobile_app_id, + policy_manager_)); if (!application) { + usage_statistics::AppCounter count_of_rejections_sync_out_of_memory( + policy_manager_, mobile_app_id, + usage_statistics::REJECTIONS_SYNC_OUT_OF_MEMORY); + ++count_of_rejections_sync_out_of_memory; + utils::SharedPtr response( MessageHelper::CreateNegativeResponse( connection_key, mobile_apis::FunctionID::RegisterAppInterfaceID, @@ -265,15 +280,20 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( application->set_name(name); application->set_device(device_id); - application->set_grammar_id(GenerateGrammarID()); - application->set_language( - static_cast( - message[strings::msg_params][strings::language_desired].asInt())); - application->set_ui_language( - static_cast( - message[strings::msg_params][strings::hmi_display_language_desired] - .asInt())); + mobile_api::Language::eType launguage_desired = + static_cast(params[strings::language_desired] + .asInt()); + application->set_language(launguage_desired); + application->usage_report().RecordAppRegistrationVuiLanguage( + launguage_desired); + + mobile_api::Language::eType hmi_display_language_desired = + static_cast(params[strings::hmi_display_language_desired] + .asInt()); + application->set_ui_language(hmi_display_language_desired); + application->usage_report().RecordAppRegistrationGuiLanguage( + hmi_display_language_desired); Version version; int32_t min_version = @@ -368,7 +388,7 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { } } if (curr_app->IsFullscreen()) { - MessageHelper::ResetGlobalproperties(curr_app); + MessageHelper::RemoveAppDataFromHMI(curr_app); } } } @@ -376,7 +396,7 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { } mobile_apis::HMILevel::eType ApplicationManagerImpl::PutApplicationInLimited( - ApplicationSharedPtr app) { + ApplicationSharedPtr app) { DCHECK(app.get()) bool is_new_app_media = app->is_media_application(); @@ -409,7 +429,7 @@ mobile_apis::HMILevel::eType ApplicationManagerImpl::PutApplicationInLimited( } mobile_api::HMILevel::eType ApplicationManagerImpl::PutApplicationInFull( - ApplicationSharedPtr app) { + ApplicationSharedPtr app) { DCHECK(app.get()) bool is_new_app_media = app->is_media_application(); @@ -446,7 +466,7 @@ mobile_api::HMILevel::eType ApplicationManagerImpl::PutApplicationInFull( } } - if ( result == mobile_api::HMILevel::HMI_FULL) { + if (result == mobile_api::HMILevel::HMI_FULL) { app->set_hmi_level(result); MessageHelper::SendActivateAppToHMI(app->app_id()); } @@ -454,6 +474,7 @@ mobile_api::HMILevel::eType ApplicationManagerImpl::PutApplicationInFull( } void ApplicationManagerImpl::DeactivateApplication(ApplicationSharedPtr app) { + MessageHelper::SendDeleteCommandRequestToHMI(app); MessageHelper::ResetGlobalproperties(app); } @@ -474,7 +495,7 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { if (true == profile::Profile::instance()->launch_hmi()) { utils::SharedPtr is_vr_ready( MessageHelper::CreateModuleInfoSO( - static_cast(hmi_apis::FunctionID::VR_IsReady))); + static_cast(hmi_apis::FunctionID::VR_IsReady))); ManageHMICommand(is_vr_ready); utils::SharedPtr is_tts_ready( @@ -613,7 +634,6 @@ void ApplicationManagerImpl::SendAudioPassThroughNotification( void ApplicationManagerImpl::StopAudioPassThru(int32_t application_key) { LOG4CXX_TRACE_ENTER(logger_); - sync_primitives::AutoLock lock(audio_pass_thru_lock_); if (NULL != media_manager_) { media_manager_->StopMicrophoneRecording(application_key); } @@ -627,7 +647,7 @@ std::string ApplicationManagerImpl::GetDeviceName( std::list applications_list; connection_handler::ConnectionHandlerImpl* con_handler_impl = static_cast( - connection_handler_); + connection_handler_); if (con_handler_impl->GetDataOnDeviceID(handle, &device_name, &applications_list) == -1) { LOG4CXX_ERROR(logger_, "Failed to extract device name for id " << handle); @@ -651,7 +671,7 @@ void ApplicationManagerImpl::OnMessageReceived( utils::SharedPtr outgoing_message = ConvertRawMsgToMessage(message); if (outgoing_message) { messages_from_mobile_.PostMessage( - impl::MessageFromMobile(outgoing_message)); + impl::MessageFromMobile(outgoing_message)); } else { LOG4CXX_WARN(logger_, "Incorrect message received"); } @@ -738,23 +758,19 @@ bool ApplicationManagerImpl::IsVideoStreamingAllowed(uint32_t connection_key) co const mobile_api::HMILevel::eType& hmi_level = app->hmi_level(); if (mobile_api::HMILevel::HMI_FULL == hmi_level && - app->hmi_supports_navi_streaming() ) { + app->hmi_supports_navi_streaming()) { return true; } return false; } -uint32_t ApplicationManagerImpl::GenerateGrammarID() { - return rand(); -} - bool ApplicationManagerImpl::OnServiceStartedCallback( - const connection_handler::DeviceHandle& device_handle, - const int32_t& session_key, - const protocol_handler::ServiceType& type) { + const connection_handler::DeviceHandle& device_handle, + const int32_t& session_key, + const protocol_handler::ServiceType& type) { LOG4CXX_INFO(logger_, - "OnServiceStartedCallback " << type << " in session " << session_key); + "OnServiceStartedCallback " << type << " in session " << session_key); ApplicationSharedPtr app = application(session_key); @@ -767,8 +783,8 @@ bool ApplicationManagerImpl::OnServiceStartedCallback( LOG4CXX_INFO(logger_, "Video service is about to be started."); if (media_manager_) { if (!app) { - LOG4CXX_ERROR_EXT(logger_, "An application is not registered."); - return false; + LOG4CXX_ERROR_EXT(logger_, "An application is not registered."); + return false; } if (app->allowed_support_navigation()) { media_manager_->StartVideoStreaming(session_key); @@ -803,7 +819,7 @@ bool ApplicationManagerImpl::OnServiceStartedCallback( } void ApplicationManagerImpl::OnServiceEndedCallback(const int32_t& session_key, - const protocol_handler::ServiceType& type) { + const protocol_handler::ServiceType& type) { LOG4CXX_INFO_EXT( logger_, "OnServiceEndedCallback " << type << " in session " << session_key); @@ -820,7 +836,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback(const int32_t& session_key, } break; } - case protocol_handler::kAudio:{ + case protocol_handler::kAudio: { LOG4CXX_INFO(logger_, "Stop audio service."); if (media_manager_) { media_manager_->StopAudioStreaming(session_key); @@ -843,11 +859,6 @@ void ApplicationManagerImpl::set_connection_handler( connection_handler_ = handler; } -void ApplicationManagerImpl::set_policy_manager( - policies::PolicyManager* policy_manager) { - policy_manager_ = policy_manager; -} - void ApplicationManagerImpl::set_protocol_handler( protocol_handler::ProtocolHandler* handler) { protocol_handler_ = handler; @@ -894,7 +905,7 @@ void ApplicationManagerImpl::SendMessageToMobile( } messages_to_mobile_.PostMessage(impl::MessageToMobile(message_to_send, - final_message)); + final_message)); } bool ApplicationManagerImpl::ManageMobileCommand( @@ -925,9 +936,9 @@ bool ApplicationManagerImpl::ManageMobileCommand( // Notifications from HMI have no such parameter uint32_t correlation_id = - (*message)[strings::params].keyExists(strings::correlation_id) - ? (*message)[strings::params][strings::correlation_id].asUInt() - : 0; + (*message)[strings::params].keyExists(strings::correlation_id) + ? (*message)[strings::params][strings::correlation_id].asUInt() + : 0; uint32_t connection_key = (*message)[strings::params][strings::connection_key].asUInt(); @@ -945,10 +956,10 @@ bool ApplicationManagerImpl::ManageMobileCommand( LOG4CXX_ERROR_EXT(logger_, "APPLICATION_NOT_REGISTERED"); smart_objects::SmartObject* response = MessageHelper::CreateNegativeResponse( - connection_key, - static_cast(function_id), - correlation_id, - static_cast(mobile_apis::Result::APPLICATION_NOT_REGISTERED)); + connection_key, + static_cast(function_id), + correlation_id, + static_cast(mobile_apis::Result::APPLICATION_NOT_REGISTERED)); ApplicationManagerImpl::instance()->SendMessageToMobile(response); return false; @@ -957,24 +968,34 @@ bool ApplicationManagerImpl::ManageMobileCommand( // Message for "CheckPermission" must be with attached schema mobile_so_factory().attachSchema(*message); - policies::CheckPermissionResult result = - policy_manager_->CheckPermission(app->app_id(), - *message, - app->hmi_level()); - - if (policies::PermissionResult::PERMISSION_ALLOWED != result.result) { - LOG4CXX_WARN( + if (policy_manager_) { + LOG4CXX_INFO( logger_, - "Request blocked by policies. " << "FunctionID: " - << static_cast(function_id) << " Application HMI status: " - << static_cast(app->hmi_level())); + "Checking permissions for " << app->mobile_app_id()->asString() << " in " << MessageHelper::StringifiedHMILevel(app->hmi_level()) << " rpc " << MessageHelper::StringifiedFunctionID(function_id)); + policy::CheckPermissionResult result = policy_manager_->CheckPermissions( + app->mobile_app_id()->asString(), + MessageHelper::StringifiedHMILevel(app->hmi_level()), + MessageHelper::StringifiedFunctionID(function_id)); + + if (app->hmi_level() == mobile_apis::HMILevel::HMI_NONE + && function_id != mobile_apis::FunctionID::UnregisterAppInterfaceID) { + app->usage_report().RecordRpcSentInHMINone(); + } - smart_objects::SmartObject* response = - MessageHelper::CreateBlockedByPoliciesResponse(function_id, - mobile_apis::Result::REJECTED, correlation_id, connection_key); + if (!result.hmi_level_permitted) { + LOG4CXX_WARN( + logger_, + "Request blocked by policies. " << "FunctionID: " << static_cast(function_id) << " Application HMI status: " << static_cast(app->hmi_level())); - ApplicationManagerImpl::instance()->SendMessageToMobile(response); - return true; + app->usage_report().RecordPolicyRejectedRpcCall(); + + smart_objects::SmartObject* response = + MessageHelper::CreateBlockedByPoliciesResponse(function_id, + mobile_apis::Result::REJECTED, correlation_id, connection_key); + + ApplicationManagerImpl::instance()->SendMessageToMobile(response); + return true; + } } } @@ -1001,10 +1022,10 @@ bool ApplicationManagerImpl::ManageMobileCommand( smart_objects::SmartObject* response = MessageHelper::CreateNegativeResponse( - connection_key, - static_cast(function_id), - correlation_id, - static_cast(mobile_apis::Result::TOO_MANY_PENDING_REQUESTS)); + connection_key, + static_cast(function_id), + correlation_id, + static_cast(mobile_apis::Result::TOO_MANY_PENDING_REQUESTS)); ApplicationManagerImpl::instance()->SendMessageToMobile(response); return false; @@ -1119,7 +1140,17 @@ bool ApplicationManagerImpl::ManageHMICommand( void ApplicationManagerImpl::CreateHMIMatrix(HMIMatrix* matrix) { } -void ApplicationManagerImpl::CreatePoliciesManager(PoliciesManager* managaer) { +void ApplicationManagerImpl::CreatePoliciesManager() { + LOG4CXX_INFO(logger_, "CreatePoliciesManager"); + policy_manager_ = policy::PolicyHandler::instance()->LoadPolicyLibrary(); + if (policy_manager_) { + LOG4CXX_INFO(logger_, "Policy library is loaded, now initing PT"); + policy::PolicyHandler::instance()->InitPolicyTable(); + // TODO(KKolodiy) in fact counter of starts + usage_statistics::GlobalCounter count_of_sync_reboots( + policy_manager_, usage_statistics::SYNC_REBOOTS); + ++count_of_sync_reboots; + } } bool ApplicationManagerImpl::CheckPolicies(smart_objects::SmartObject* message, @@ -1148,10 +1179,10 @@ bool ApplicationManagerImpl::ConvertMessageToSO( message.function_id(), message.type(), message.correlation_id()) - || !mobile_so_factory().attachSchema(output) - || ((output.validate() != smart_objects::Errors::OK) - && (output.validate() != - smart_objects::Errors::UNEXPECTED_PARAMETER))) { + || !mobile_so_factory().attachSchema(output) + || ((output.validate() != smart_objects::Errors::OK) + && (output.validate() != + smart_objects::Errors::UNEXPECTED_PARAMETER))) { LOG4CXX_WARN(logger_, "Failed to parse string to smart object"); utils::SharedPtr response( MessageHelper::CreateNegativeResponse( @@ -1174,8 +1205,8 @@ bool ApplicationManagerImpl::ConvertMessageToSO( } case ProtocolVersion::kHMI: { int32_t result = formatters::FormatterJsonRpc::FromString < - hmi_apis::FunctionID::eType, hmi_apis::messageType::eType > ( - message.json_message(), output); + hmi_apis::FunctionID::eType, hmi_apis::messageType::eType > ( + message.json_message(), output); LOG4CXX_INFO( logger_, "Convertion result: " << result << " function id " @@ -1198,40 +1229,40 @@ bool ApplicationManagerImpl::ConvertMessageToSO( break; } case ProtocolVersion::kV1: { - static NsSmartDeviceLinkRPC::V1::v4_protocol_v1_2_no_extra v1_shema; + static NsSmartDeviceLinkRPC::V1::v4_protocol_v1_2_no_extra v1_shema; - if (message.function_id() == 0 || message.type() == kUnknownType) { - LOG4CXX_ERROR(logger_, "Message received: UNSUPPORTED_VERSION"); + if (message.function_id() == 0 || message.type() == kUnknownType) { + LOG4CXX_ERROR(logger_, "Message received: UNSUPPORTED_VERSION"); - int32_t conversation_result = - formatters::CFormatterJsonSDLRPCv1::fromString < - NsSmartDeviceLinkRPC::V1::FunctionID::eType, - NsSmartDeviceLinkRPC::V1::messageType::eType > ( - message.json_message(), output); + int32_t conversation_result = + formatters::CFormatterJsonSDLRPCv1::fromString < + NsSmartDeviceLinkRPC::V1::FunctionID::eType, + NsSmartDeviceLinkRPC::V1::messageType::eType > ( + message.json_message(), output); - if (formatters::CFormatterJsonSDLRPCv1::kSuccess - == conversation_result) { + if (formatters::CFormatterJsonSDLRPCv1::kSuccess + == conversation_result) { - smart_objects::SmartObject params = smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); + smart_objects::SmartObject params = smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); - output[strings::params][strings::message_type] = - NsSmartDeviceLinkRPC::V1::messageType::response; - output[strings::params][strings::connection_key] = message.connection_key(); + output[strings::params][strings::message_type] = + NsSmartDeviceLinkRPC::V1::messageType::response; + output[strings::params][strings::connection_key] = message.connection_key(); - output[strings::msg_params] = - smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); - output[strings::msg_params][strings::success] = false; - output[strings::msg_params][strings::result_code] = - NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION; + output[strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); + output[strings::msg_params][strings::success] = false; + output[strings::msg_params][strings::result_code] = + NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION; - smart_objects::SmartObject* msg_to_send = new smart_objects::SmartObject(output); - v1_shema.attachSchema(*msg_to_send); - SendMessageToMobile(msg_to_send); - return false; - } + smart_objects::SmartObject* msg_to_send = new smart_objects::SmartObject(output); + v1_shema.attachSchema(*msg_to_send); + SendMessageToMobile(msg_to_send); + return false; } + } - break; + break; } default: // TODO(PV): @@ -1266,23 +1297,22 @@ bool ApplicationManagerImpl::ConvertSOtoMessage( std::string output_string; switch (message.getElement(jhs::S_PARAMS).getElement(jhs::S_PROTOCOL_TYPE) .asInt()) { - case 0: - { - if (message.getElement(jhs::S_PARAMS).getElement(jhs::S_PROTOCOL_VERSION).asInt() == 1) { - if (!formatters::CFormatterJsonSDLRPCv1::toString(message, - output_string)) { - LOG4CXX_WARN(logger_, "Failed to serialize smart object"); - return false; - } - output.set_protocol_version(application_manager::kV1); - } else { - if (!formatters::CFormatterJsonSDLRPCv2::toString(message, - output_string)) { - LOG4CXX_WARN(logger_, "Failed to serialize smart object"); - return false; - } - output.set_protocol_version(application_manager::kV2); + case 0: { + if (message.getElement(jhs::S_PARAMS).getElement(jhs::S_PROTOCOL_VERSION).asInt() == 1) { + if (!formatters::CFormatterJsonSDLRPCv1::toString(message, + output_string)) { + LOG4CXX_WARN(logger_, "Failed to serialize smart object"); + return false; + } + output.set_protocol_version(application_manager::kV1); + } else { + if (!formatters::CFormatterJsonSDLRPCv2::toString(message, + output_string)) { + LOG4CXX_WARN(logger_, "Failed to serialize smart object"); + return false; } + output.set_protocol_version(application_manager::kV2); + } break; } @@ -1495,6 +1525,18 @@ void ApplicationManagerImpl::SetUnregisterAllApplicationsReason( unregister_reason_ = reason; } +void ApplicationManagerImpl::HeadUnitReset( + mobile_api::AppInterfaceUnregisteredReason::eType reason) { + switch (reason) { + case mobile_api::AppInterfaceUnregisteredReason::MASTER_RESET: + policy::PolicyHandler::instance()->InitPolicyTable(); + break; + case mobile_api::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS: + policy::PolicyHandler::instance()->RevertPolicyTable(); + break; + } +} + void ApplicationManagerImpl::UnregisterAllApplications() { LOG4CXX_INFO(logger_, "ApplicationManagerImpl::UnregisterAllApplications " << unregister_reason_); @@ -1534,7 +1576,7 @@ void ApplicationManagerImpl::UnregisterApplication( StopAudioPassThru(app_id); MessageHelper::SendStopAudioPathThru(); } - MessageHelper::ResetGlobalproperties(it->second); + MessageHelper::RemoveAppDataFromHMI(it->second); MessageHelper::SendOnAppUnregNotificationToHMI(it->second); applications_.erase(it); application_list_.erase(app_to_remove); @@ -1605,9 +1647,9 @@ void ApplicationManagerImpl::Handle(const impl::MessageToHmi& message) { void ApplicationManagerImpl::Mute(VRTTSSessionChanging changing_state) { mobile_apis::AudioStreamingState::eType state = - hmi_capabilities_.attenuated_supported() - ? mobile_apis::AudioStreamingState::ATTENUATED - : mobile_apis::AudioStreamingState::NOT_AUDIBLE; + hmi_capabilities_.attenuated_supported() + ? mobile_apis::AudioStreamingState::ATTENUATED + : mobile_apis::AudioStreamingState::NOT_AUDIBLE; std::set::const_iterator it = application_list_.begin(); std::set::const_iterator itEnd = application_list_.end(); @@ -1634,9 +1676,9 @@ void ApplicationManagerImpl::Unmute(VRTTSSessionChanging changing_state) { } if ((!(vr_session_started())) && ((*it)->audio_streaming_state() != - mobile_apis::AudioStreamingState::AUDIBLE)) { + mobile_apis::AudioStreamingState::AUDIBLE)) { (*it)->set_audio_streaming_state( - mobile_apis::AudioStreamingState::AUDIBLE); + mobile_apis::AudioStreamingState::AUDIBLE); MessageHelper::SendHMIStatusNotification(*(*it)); } } @@ -1644,12 +1686,12 @@ void ApplicationManagerImpl::Unmute(VRTTSSessionChanging changing_state) { } mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary( - const std::vector& binary_data, const std::string& file_path, - const uint32_t offset) { + const std::vector& binary_data, const std::string& file_path, + const uint32_t offset) { LOG4CXX_INFO( - logger_, - "SaveBinaryWithOffset binary_size = " << binary_data.size() - << " offset = " << offset); + logger_, + "SaveBinaryWithOffset binary_size = " << binary_data.size() + << " offset = " << offset); if (binary_data.size() > file_system::GetAvailableDiskSpace()) { LOG4CXX_ERROR(logger_, "Out of free disc space."); @@ -1661,15 +1703,15 @@ mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary( if (offset != 0) { if (file_size != offset) { LOG4CXX_INFO( - logger_, - "ApplicationManagerImpl::SaveBinaryWithOffset offset does'n match existing filesize"); + logger_, + "ApplicationManagerImpl::SaveBinaryWithOffset offset does'n match existing filesize"); return mobile_apis::Result::INVALID_DATA; } file_stream = file_system::Open(file_path, std::ios_base::app); } else { LOG4CXX_INFO( - logger_, - "ApplicationManagerImpl::SaveBinaryWithOffset offset is 0, rewrite"); + logger_, + "ApplicationManagerImpl::SaveBinaryWithOffset offset is 0, rewrite"); // if offset == 0: rewrite file file_stream = file_system::Open(file_path, std::ios_base::out); } diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index 704c701..12c37c5 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -278,6 +278,12 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( smart_objects::SmartType_Map); if (!params) { + std::string mobile_app_id = + (*message_)[strings::msg_params][strings::app_id].asString(); + usage_statistics::AppCounter count_of_rejections_sync_out_of_memory( + policy::PolicyHandler::instance()->policy_manager(), mobile_app_id, + usage_statistics::REJECTIONS_SYNC_OUT_OF_MEMORY); + ++count_of_rejections_sync_out_of_memory; SendResponse(false, mobile_apis::Result::OUT_OF_MEMORY); return; } @@ -757,7 +763,8 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { LOG4CXX_INFO(logger_, "RegisterAppInterfaceRequest::IsApplicationRegistered"); - const std::string& mobile_app_id = (*message_)[strings::msg_params][strings::app_id].asString(); + int32_t mobile_app_id = (*message_)[strings::msg_params][strings::app_id] + .asInt(); const std::set& applications = ApplicationManagerImpl::instance()->applications(); @@ -766,7 +773,7 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { std::set::const_iterator it_end = applications.end(); for (; it != it_end; ++it) { - if (mobile_app_id == (*it)->mobile_app_id()->asString()) { + if (mobile_app_id == (*it)->mobile_app_id()->asInt()) { return true; } } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 7aae9c5..122d6bc 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -44,6 +44,7 @@ #include "utils/date_time.h" #include "json/value.h" #include "config_profile/profile.h" +#include "application_manager/usage_statistics.h" namespace policy { typedef std::set> ApplicationList; @@ -468,8 +469,20 @@ void PolicyHandler::OnActivateApp(const std::string& policy_app_id, // - isSDLAllowed, i.e. device data usage consent AppPermissions permissions(atoi(policy_app_id.c_str())); + + application_manager::UsageStatistics& usage = + application_manager::ApplicationManagerImpl::instance()->application( + permissions.application_id)->usage_report(); + + usage.RecordAppUserSelection(); + DeviceConsent consent = GetDeviceForSending(permissions.deviceInfo); permissions.isSDLAllowed = kDeviceAllowed == consent ? true : false; + permissions.appRevoked = policy_manager_->IsApplicationRevoked(policy_app_id); + + if (permissions.appRevoked) { + usage.RecordRunAttemptsWhileRevoked(); + } // If isSDLAllowed is false, we should provide device params for user consent if (!permissions.isSDLAllowed) { diff --git a/src/components/application_manager/src/usage_statistics.cc b/src/components/application_manager/src/usage_statistics.cc index 18cd5c3..87cf68d 100644 --- a/src/components/application_manager/src/usage_statistics.cc +++ b/src/components/application_manager/src/usage_statistics.cc @@ -32,6 +32,7 @@ #include "application_manager/usage_statistics.h" +#include "smart_objects/smart_object.h" #include "smart_objects/enum_schema_item.h" #include "usage_statistics/statistics_manager.h" #include "utils/macro.h" @@ -47,7 +48,7 @@ namespace { std::string LanguageIdToString(Language::eType lang_id) { typedef std::map EnumMap; const EnumMap& enum_map = - TEnumSchemaItem::getEnumElementsStringRepresentation(); + TEnumSchemaItem::getEnumElementsStringRepresentation(); EnumMap::const_iterator found = enum_map.find(lang_id); if (found != enum_map.end()) { return found->second; @@ -58,26 +59,26 @@ std::string LanguageIdToString(Language::eType lang_id) { } // namespace -ApplicationUsageReport::ApplicationUsageReport( +UsageStatistics::UsageStatistics( const std::string& app_id, usage_statistics::StatisticsManager* statistics_manager) - : time_in_hmi_state_(statistics_manager, app_id), - app_registration_language_gui_(statistics_manager, app_id, - LANGUAGE_GUI), - app_registration_language_vui_(statistics_manager, app_id, - LANGUAGE_VUI), - count_of_rejected_rpc_calls_(statistics_manager, app_id, - REJECTED_RPC_CALLS), - count_of_rpcs_sent_in_hmi_none_(statistics_manager, app_id, - RPCS_IN_HMI_NONE) { + : time_in_hmi_state_(statistics_manager, app_id), + app_registration_language_gui_(statistics_manager, app_id, LANGUAGE_GUI), + app_registration_language_vui_(statistics_manager, app_id, LANGUAGE_VUI), + count_of_rejected_rpc_calls_(statistics_manager, app_id, + REJECTED_RPC_CALLS), + count_of_rpcs_sent_in_hmi_none_(statistics_manager, app_id, + RPCS_IN_HMI_NONE), + count_of_user_selections_(statistics_manager, app_id, USER_SELECTIONS), + count_of_run_attempts_while_revoked_(statistics_manager, app_id, + RUN_ATTEMPTS_WHILE_REVOKED) { time_in_hmi_state_.Start(SECONDS_HMI_NONE); } -void ApplicationUsageReport::RecordHmiStateChanged( - mobile_apis::HMILevel::eType new_hmi_level) { +void UsageStatistics::RecordHmiStateChanged(HMILevel::eType new_hmi_level) { using namespace mobile_apis::HMILevel; AppStopwatchId next_stopwatch = SECONDS_HMI_NONE; - switch(new_hmi_level) { + switch (new_hmi_level) { case HMI_FULL: next_stopwatch = SECONDS_HMI_FULL; break; @@ -91,27 +92,36 @@ void ApplicationUsageReport::RecordHmiStateChanged( next_stopwatch = SECONDS_HMI_NONE; break; default: - NOTREACHED(); + NOTREACHED() + ; } time_in_hmi_state_.Switch(next_stopwatch); } -void ApplicationUsageReport::RecordAppRegistrationGuiLanguage( +void UsageStatistics::RecordAppRegistrationGuiLanguage( Language::eType gui_language) { app_registration_language_gui_.Update(LanguageIdToString(gui_language)); } -void ApplicationUsageReport::RecordAppRegistrationVuiLanguage( - mobile_apis::Language::eType vui_language) { +void UsageStatistics::RecordAppRegistrationVuiLanguage( + Language::eType vui_language) { app_registration_language_gui_.Update(LanguageIdToString(vui_language)); } -void ApplicationUsageReport::RecordRpcSentInHMINone() { +void UsageStatistics::RecordRpcSentInHMINone() { ++count_of_rpcs_sent_in_hmi_none_; } -void ApplicationUsageReport::RecordPolicyRejectedRpcCall() { +void UsageStatistics::RecordPolicyRejectedRpcCall() { ++count_of_rejected_rpc_calls_; } +void UsageStatistics::RecordAppUserSelection() { + ++count_of_user_selections_; +} + +void UsageStatistics::RecordRunAttemptsWhileRevoked() { + ++count_of_run_attempts_while_revoked_; +} + } // namespace application_manager -- 2.7.4