APPLINK-6400:
authorKonstantin Kolodiy <KKolodiy@luxoft.com>
Fri, 4 Apr 2014 16:06:05 +0000 (20:06 +0400)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 8 Jul 2014 22:53:25 +0000 (18:53 -0400)
- Implemente count_of_run_attempts_while_revoked, count_of_removals_for_bad_behavior

Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Conflicts:
src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc

src/components/application_manager/include/application_manager/application_manager_impl.h
src/components/application_manager/include/application_manager/usage_statistics.h
src/components/application_manager/src/application_manager_impl.cc
src/components/application_manager/src/commands/hmi/on_exit_application_notification.cc
src/components/application_manager/src/commands/hmi/on_tts_language_change_notification.cc
src/components/application_manager/src/commands/hmi/on_ui_language_change_notification.cc
src/components/application_manager/src/commands/hmi/on_vr_language_change_notification.cc
src/components/application_manager/src/commands/mobile/unregister_app_interface_request.cc
src/components/application_manager/src/usage_statistics.cc

index 2fc82cd..723b21e 100644 (file)
@@ -195,10 +195,13 @@ class ApplicationManagerImpl : public ApplicationManager,
      * @brief Closes application by id
      *
      * @param app_id Application id
+     * @param reason reason of unregistering application
      * @param is_resuming describes - is this unregister
      *        is normal or need to be resumed
      */
-    void UnregisterApplication(const uint32_t& app_id, bool is_resuming = false);
+    void UnregisterApplication(const uint32_t& app_id,
+                               mobile_apis::Result::eType reason,
+                               bool is_resuming = false);
 
     /*
      * @brief Sets unregister reason for closing all registered applications
index 0d3571c..188a364 100644 (file)
@@ -52,6 +52,7 @@ class UsageStatistics {
   void RecordPolicyRejectedRpcCall();
   void RecordAppUserSelection();
   void RecordRunAttemptsWhileRevoked();
+  void RecordRemovalsForBadBehavior();
 
  private:
   usage_statistics::AppStopwatch time_in_hmi_state_;
@@ -61,6 +62,7 @@ class UsageStatistics {
   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_;
+  usage_statistics::AppCounter count_of_removals_for_bad_behavior_;
 };
 
 }  // namespace application_manager
index 69cb88c..c12d9a0 100644 (file)
@@ -258,8 +258,8 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication(
   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_));
+  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,
@@ -826,7 +826,8 @@ void ApplicationManagerImpl::OnServiceEndedCallback(const int32_t& session_key,
   switch (type) {
     case protocol_handler::kRpc: {
       LOG4CXX_INFO(logger_, "Remove application.");
-      UnregisterApplication(session_key, true);
+      UnregisterApplication(session_key, mobile_apis::Result::INVALID_ENUM,
+                            true);
       break;
     }
     case protocol_handler::kMobileNav: {
@@ -1038,7 +1039,9 @@ bool ApplicationManagerImpl::ManageMobileCommand(
           connection_key,
           mobile_api::AppInterfaceUnregisteredReason::TOO_MANY_REQUESTS);
 
-        UnregisterApplication(connection_key, true);
+        UnregisterApplication(connection_key,
+                              mobile_apis::Result::TOO_MANY_PENDING_REQUESTS,
+                              true);
         return false;
       } else if (result ==
                  request_controller::RequestController::
@@ -1050,7 +1053,8 @@ bool ApplicationManagerImpl::ManageMobileCommand(
           connection_key, mobile_api::AppInterfaceUnregisteredReason::
           REQUEST_WHILE_IN_NONE_HMI_LEVEL);
 
-        UnregisterApplication(connection_key, true);
+        UnregisterApplication(connection_key, mobile_apis::Result::INVALID_ENUM,
+                              true);
         return false;
       } else {
         LOG4CXX_ERROR_EXT(logger_, "Unable to perform request: Unknown case");
@@ -1534,26 +1538,39 @@ void ApplicationManagerImpl::HeadUnitReset(
 }
 
 void ApplicationManagerImpl::UnregisterAllApplications() {
-  LOG4CXX_INFO(logger_, "ApplicationManagerImpl::UnregisterAllApplications "  <<
-               unregister_reason_);
+  LOG4CXX_INFO(logger_, "ApplicationManagerImpl::UnregisterAllApplications " <<
+      unregister_reason_);
 
   hmi_cooperating_ = false;
 
   std::set<ApplicationSharedPtr>::iterator it = application_list_.begin();
   while (it != application_list_.end()) {
     MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
-      (*it)->app_id(), unregister_reason_);
+        (*it)->app_id(), unregister_reason_);
 
-    UnregisterApplication((*it)->app_id(), true);
+    UnregisterApplication((*it)->app_id(), mobile_apis::Result::INVALID_ENUM,
+                          true);
     it = application_list_.begin();
   }
   resume_controller().IgnitionOff();
 }
 
 void ApplicationManagerImpl::UnregisterApplication(
-    const uint32_t& app_id, bool is_resuming) {
+    const uint32_t& app_id, mobile_apis::Result::eType reason,
+    bool is_resuming) {
   LOG4CXX_INFO(logger_,
-               "ApplicationManagerImpl::UnregisterApplication " << app_id);
+      "ApplicationManagerImpl::UnregisterApplication " << app_id);
+
+  switch (reason) {
+    case mobile_apis::Result::DISALLOWED:
+    case mobile_apis::Result::USER_DISALLOWED:
+    case mobile_apis::Result::INVALID_CERT:
+    case mobile_apis::Result::EXPIRED_CERT:
+    case mobile_apis::Result::TOO_MANY_PENDING_REQUESTS: {
+      application(app_id)->usage_report().RecordRemovalsForBadBehavior();
+      break;
+    }
+  }
 
   sync_primitives::AutoLock lock(applications_list_lock_);
 
@@ -1594,11 +1611,9 @@ void ApplicationManagerImpl::Handle(const impl::MessageFromMobile& message) {
 void ApplicationManagerImpl::Handle(const impl::MessageToMobile& message) {
   protocol_handler::RawMessage* rawMessage = 0;
   if (message->protocol_version() == application_manager::kV1) {
-    rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV1(
-                   message);
+    rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV1(message);
   } else if (message->protocol_version() == application_manager::kV2) {
-    rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV2(
-                   message);
+    rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV2(message);
   } else {
     return;
   }
index de4e29d..9d5e5d6 100644 (file)
@@ -32,9 +32,6 @@
 
 #include "application_manager/commands/hmi/on_exit_application_notification.h"
 #include "application_manager/application_manager_impl.h"
-#include "application_manager/application_impl.h"
-#include "application_manager/message_helper.h"
-#include "interfaces/MOBILE_API.h"
 
 namespace application_manager {
 
@@ -50,16 +47,9 @@ OnExitApplicationNotification::~OnExitApplicationNotification() {
 void OnExitApplicationNotification::Run() {
   LOG4CXX_INFO(logger_, "OnExitApplicationNotification::Run");
 
-  ApplicationManagerImpl* app_mgr = ApplicationManagerImpl::instance();
-  ApplicationSharedPtr app_impl = app_mgr->application(
-      (*message_)[strings::msg_params][strings::app_id].asUInt());
-  if (!(app_impl.valid())) {
-    LOG4CXX_ERROR(logger_, "Application does not exist");
-    return;
-  }
-  app_impl->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
-  app_impl->set_audio_streaming_state(mobile_apis::AudioStreamingState::NOT_AUDIBLE);
-  MessageHelper::SendHMIStatusNotification(*app_impl);
+  ApplicationManagerImpl::instance()->UnregisterApplication(
+      (*message_)[strings::msg_params][strings::app_id].asUInt(),
+      mobile_apis::Result::SUCCESS);
 }
 
 }  // namespace commands
index 0a20c59..458b926 100644 (file)
@@ -84,7 +84,8 @@ void OnTTSLanguageChangeNotification::Run() {
       MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
-      ApplicationManagerImpl::instance()->UnregisterApplication(app->app_id(), true);
+      ApplicationManagerImpl::instance()->UnregisterApplication(
+          app->app_id(), mobile_apis::Result::SUCCESS, true);
     }
   }
 }
index 115ff38..46dda8d 100644 (file)
@@ -82,7 +82,8 @@ void OnUILanguageChangeNotification::Run() {
       MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
-      ApplicationManagerImpl::instance()->UnregisterApplication(app->app_id(), true);
+      ApplicationManagerImpl::instance()->UnregisterApplication(
+          app->app_id(), mobile_apis::Result::SUCCESS, true);
     }
   }
 }
index dcc5355..c18b197 100644 (file)
@@ -79,7 +79,8 @@ void OnVRLanguageChangeNotification::Run() {
       MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
-      ApplicationManagerImpl::instance()->UnregisterApplication(app->app_id(), true);
+      ApplicationManagerImpl::instance()->UnregisterApplication(
+          app->app_id(), mobile_apis::Result::SUCCESS, true);
     }
   }
 }
index 0fc1d1f..a07cfcd 100644 (file)
@@ -50,7 +50,8 @@ void UnregisterAppInterfaceRequest::Run() {
     return;
   }
 
-  app_manager->UnregisterApplication(connection_key());
+  app_manager->UnregisterApplication(connection_key(),
+                                     mobile_apis::Result::SUCCESS);
   SendResponse(true, mobile_apis::Result::SUCCESS);
 }
 
index 87cf68d..9a7eac1 100644 (file)
@@ -71,7 +71,9 @@ UsageStatistics::UsageStatistics(
                                       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) {
+                                           RUN_ATTEMPTS_WHILE_REVOKED),
+      count_of_removals_for_bad_behavior_(statistics_manager, app_id,
+                                          REMOVALS_MISBEHAVED) {
   time_in_hmi_state_.Start(SECONDS_HMI_NONE);
 }
 
@@ -124,4 +126,8 @@ void UsageStatistics::RecordRunAttemptsWhileRevoked() {
   ++count_of_run_attempts_while_revoked_;
 }
 
+void UsageStatistics::RecordRemovalsForBadBehavior() {
+  ++count_of_removals_for_bad_behavior_;
+}
+
 }  // namespace application_manager