Application manager updates
authorJustin Dickow <jjdickow@gmail.com>
Thu, 17 Jul 2014 17:39:47 +0000 (13:39 -0400)
committerJustin Dickow <jjdickow@gmail.com>
Thu, 17 Jul 2014 17:39:47 +0000 (13:39 -0400)
Authors

Alex Kutsan
Alexander Kutsan
Andrey Oleynik
Dmitriy Klimenko
Dmitriy Trunov
Dmitry Chmerev
Igor Kozyrenko
Kandul Alexander
Konstantin Kolodiy
Newton Kim
Nikolay Khlopkov
Polina Vyshnevska
Victor Slobodyanik
Vladislav Smenyuk

Signed-off-by: Justin Dickow <jjdickow@gmail.com>
32 files changed:
src/components/application_manager/CMakeLists.txt
src/components/application_manager/include/application_manager/application_manager_impl.h
src/components/application_manager/include/application_manager/message_helper.h
src/components/application_manager/include/application_manager/policies/policy_handler.h
src/components/application_manager/include/application_manager/policies/pt_exchange_handler.h
src/components/application_manager/include/application_manager/resume_ctrl.h
src/components/application_manager/include/application_manager/smart_object_keys.h
src/components/application_manager/src/application_manager_impl.cc
src/components/application_manager/src/commands/hmi/activate_app_response.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/alert_maneuver_request.cc
src/components/application_manager/src/commands/mobile/alert_request.cc
src/components/application_manager/src/commands/mobile/delete_command_request.cc
src/components/application_manager/src/commands/mobile/delete_interaction_choice_set_request.cc
src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc
src/components/application_manager/src/commands/mobile/diagnostic_message_request.cc
src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc
src/components/application_manager/src/commands/mobile/perform_interaction_request.cc
src/components/application_manager/src/commands/mobile/put_file_request.cc
src/components/application_manager/src/commands/mobile/register_app_interface_request.cc
src/components/application_manager/src/commands/mobile/register_app_interface_response.cc
src/components/application_manager/src/commands/mobile/scrollable_message_request.cc
src/components/application_manager/src/commands/mobile/show_constant_tbt_request.cc
src/components/application_manager/src/commands/mobile/show_request.cc
src/components/application_manager/src/commands/mobile/speak_request.cc
src/components/application_manager/src/message_helper.cc
src/components/application_manager/src/policies/policy_handler.cc
src/components/application_manager/src/policies/pt_exchange_handler_ext.cc
src/components/application_manager/src/request_controller.cc

index ea98188..98b0640 100644 (file)
@@ -23,7 +23,6 @@ include_directories (
   ${CMAKE_BINARY_DIR}/src/components/
   ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/include/
   ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/usage_statistics/include/
-  ${CMAKE_BINARY_DIR}/src/components/policy/src/policy/
 )
 
 set (SOURCES
@@ -49,11 +48,17 @@ set (POLICIES_MANAGER
 )
 
 if (EXTENDED_POLICY_FLAG)
+  include_directories(
+    ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/policy_table/table_struct_ext
+  )
   list(APPEND POLICIES_MANAGER
     ./src/policies/pt_exchange_handler_ext.cc
     ./src/policies/pt_exchange_handler_impl.cc
   )
 else ()
+  include_directories(
+    ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/policy_table/table_struct
+  )
   list(APPEND POLICIES_MANAGER
     ./src/policies/pt_exchange_handler_impl.cc
   )
@@ -414,5 +419,6 @@ add_library("ApplicationManager" ${SOURCES} ${MOBILE_COMMANDS_SOURCES} ${HMI_COM
 target_link_libraries("ApplicationManager" ${LIBRARIES})
 
 if(ENABLE_LOG)
-  target_link_libraries("ApplicationManager" log4cxx)
+  add_dependencies("ApplicationManager" liblog4cxx)
+  target_link_libraries("ApplicationManager" log4cxx -L${LOG4CXX_LIBS_DIRECTORY})
 endif()
index d4765b4..f9d257f 100644 (file)
@@ -60,7 +60,9 @@
 
 #include "interfaces/v4_protocol_v1_2_no_extra.h"
 #include "interfaces/v4_protocol_v1_2_no_extra_schema.h"
+#ifdef TIME_TESTER
 #include "time_metric_observer.h"
+#endif  // TIME_TESTER
 #include "protocol_handler/service_type.h"
 
 #include "utils/macro.h"
@@ -212,12 +214,14 @@ class ApplicationManagerImpl : public ApplicationManager,
 
     HMICapabilities& hmi_capabilities();
 
+#ifdef TIME_TESTER
     /**
      * @brief Setup observer for time metric.
      *
      * @param observer - pointer to observer
      */
     void SetTimeMetricObserver(AMMetricObserver* observer);
+#endif  // TIME_TESTER
 
     ApplicationSharedPtr RegisterApplication(
       const utils::SharedPtr<smart_objects::SmartObject>& request_for_registration);
@@ -371,6 +375,7 @@ class ApplicationManagerImpl : public ApplicationManager,
 
     void set_hmi_message_handler(hmi_message_handler::HMIMessageHandler* handler);
     void set_connection_handler(connection_handler::ConnectionHandler* handler);
+    connection_handler::ConnectionHandler* connection_handler();
     void set_protocol_handler(protocol_handler::ProtocolHandler* handler);
 
     ///////////////////////////////////////////////////////
@@ -407,6 +412,8 @@ class ApplicationManagerImpl : public ApplicationManager,
     void OnErrorSending(hmi_message_handler::MessageSharedPointer message);
 
     void OnDeviceListUpdated(const connection_handler::DeviceList& device_list);
+    //TODO (EZamakhov): fix all indentations in this file
+    void OnApplicationListUpdated(const connection_handler::DeviceHandle& device_handle);
     void RemoveDevice(const connection_handler::DeviceHandle& device_handle);
   bool OnServiceStartedCallback(
       const connection_handler::DeviceHandle& device_handle,
@@ -553,6 +560,13 @@ class ApplicationManagerImpl : public ApplicationManager,
      */
     bool IsHMICooperating() const;
 
+    /**
+     * Function used only by HMI request/response/notification base classes
+     * to change HMI app id to Mobile app id and vice versa.
+     * Dot use it inside Core
+     */
+    ApplicationSharedPtr application_by_hmi_app(int32_t hmi_app_id) const;
+
   private:
     ApplicationManagerImpl();
     bool InitThread(threads::Thread* thread);
@@ -608,14 +622,7 @@ class ApplicationManagerImpl : public ApplicationManager,
     virtual void Handle(const impl::MessageFromHmi& message) OVERRIDE;
 
     // CALLED ON messages_to_hmi_ thread!
-    virtual void Handle(const impl::MessageToHmi& message) OVERRIDE;
-
-    /**
-     * Function used only by HMI request/response/notification base classes
-     * to change HMI app id to Mobile app id and vice versa.
-     * Dot use it inside Core
-     */
-    ApplicationSharedPtr application_by_hmi_app(int32_t hmi_app_id) const;
+    virtual void Handle(const impl::MessageToHmi& message) OVERRIDE;    
 
   private:
 
@@ -665,7 +672,9 @@ class ApplicationManagerImpl : public ApplicationManager,
     hmi_apis::HMI_API*                      hmi_so_factory_;
     mobile_apis::MOBILE_API*                mobile_so_factory_;
 
+#ifdef TIME_TESTER
     AMMetricObserver* metric_observer_;
+#endif  // TIME_TESTER
     static uint32_t corelation_id_;
     static const uint32_t max_corelation_id_;
 
index 4161cf2..ca240f5 100644 (file)
@@ -54,33 +54,6 @@ namespace mobile_api = mobile_apis;
 namespace smart_objects = NsSmartDeviceLink::NsSmartObjects;
 
 /*
- * @brief Typedef for HMI TextFieldName type
- */
-typedef enum {
-  MAIN_FILED1 = 0,
-  MAIN_FILED2,
-  MAIN_FILED3,
-  MAIN_FILED4,
-  STATUS_BAR,
-  MEDIA_CLOCK,
-  MEDIA_TRACK,
-  ALERT_TEXT1,
-  ALERT_TEXT2,
-  ALERT_TEXT3,
-  SCROLLABLE_MSG_BODY,
-  INITIAL_INTERACTION_TEXT,
-  NAVI_TEXT1,
-  NAVI_TEXT2,
-  ETA,
-  TOTAL_DISTANCE,
-  NAVI_TEXT,
-  AUDIO_DISPLAY_TEXT1,
-  AUDIO_DISPLAY_TEXT2,
-  SLIDER_HADER,
-  SLIDER_FOOTEER
-} TextFieldName;
-
-/*
  * @brief Typedef for VehicleData
  *
  * @param const char* Name of the parameter in mobile request
@@ -225,6 +198,15 @@ class MessageHelper {
       uint32_t cmd_id, const smart_objects::SmartObject& vr_commands,
       uint32_t app_id);
 
+    /*
+     * @brief Create Common.HMIApplication struct application instance
+     * @param app : applicaton instace
+     * @param output smart object to store Common.HMIApplication struct
+     * @return true on succes, otherwise return false;
+     */
+    static bool CreateHMIApplicationStruct(ApplicationConstSharedPtr app,
+                                      smart_objects::SmartObject& output);
+
     static void SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app);
     static SmartObjectList CreateAddSubMenuRequestToHMI(ApplicationConstSharedPtr app);
 
@@ -232,12 +214,14 @@ class MessageHelper {
     static void SendOnAppUnregNotificationToHMI(ApplicationConstSharedPtr app);
     static void ResetGlobalproperties(ApplicationSharedPtr app);
 
-    static void SendActivateAppToHMI(uint32_t const app_id);
+    static void SendActivateAppToHMI(
+      uint32_t const app_id,
+      hmi_apis::Common_HMILevel::eType level = hmi_apis::Common_HMILevel::FULL);
 
     static void SendOnResumeAudioSourceToHMI(const uint32_t app_id);
 
     static std::string GetDeviceMacAddressForHandle(
-        const uint32_t device_handle);
+      const uint32_t device_handle);
 
     static void GetDeviceInfoForHandle(const uint32_t device_handle,
                                        policy::DeviceParams* device_info);
@@ -414,10 +398,10 @@ class MessageHelper {
      *
      */
     static mobile_apis::Result::eType VerifyImageFiles(
-        smart_objects::SmartObject& message, ApplicationConstSharedPtr app);
+      smart_objects::SmartObject& message, ApplicationConstSharedPtr app);
 
     static mobile_apis::Result::eType VerifyImageVrHelpItems(
-        smart_objects::SmartObject& message, ApplicationConstSharedPtr app);
+      smart_objects::SmartObject& message, ApplicationConstSharedPtr app);
 
     static bool VerifySoftButtonText(smart_objects::SmartObject& soft_button);
 
index 8929ca2..05d1a1a 100644 (file)
@@ -63,7 +63,8 @@ class PolicyHandler : public utils::Singleton<PolicyHandler>,
     return policy_manager_;
   }
   bool InitPolicyTable();
-  bool RevertPolicyTable();
+  bool ResetPolicyTable();
+  bool ClearUserConsent();
   bool SendMessageToSDK(const BinaryMessage& pt_string);
   bool ReceiveMessageFromSDK(const std::string& file,
                              const BinaryMessage& pt_string);
@@ -222,6 +223,12 @@ class PolicyHandler : public utils::Singleton<PolicyHandler>,
 
   std::string GetAppName(const std::string& policy_app_id);
 
+  /**
+   * Adds http header (temporary method)
+   * @param pt_string string without htt header
+   */
+  BinaryMessageSptr AddHttpHeader(const BinaryMessageSptr& pt_string);
+
  protected:
   /**
    * Starts next retry exchange policy table
@@ -273,18 +280,6 @@ class PolicyHandler : public utils::Singleton<PolicyHandler>,
    */
   DeviceHandles pending_device_handles_;
 
-  /**
-   * @brief True, if PTS was sent, but PTU was not reseived yet,
-   * otherwise - false
-   * Used for limiting device consent request per PTS/PTU session
-   */
-  bool is_exchange_in_progress_;
-
-  /**
-   * @brief Holds device ids, which were unpaired
-   */
-  DeviceIds unpaired_device_ids_;
-
   inline PolicyManager* CreateManager();
 
   DISALLOW_COPY_AND_ASSIGN(PolicyHandler);FRIEND_BASE_SINGLETON_CLASS(PolicyHandler);
index 93d9484..5b291dc 100644 (file)
 
 namespace policy {
 class PTExchangeHandler {
- public:
-  virtual ~PTExchangeHandler();
-  virtual bool StartExchange() = 0;
-  // TODO(PV): exchange status; exchange completed; retry etc
-
+  public:
+    virtual ~PTExchangeHandler();
+    virtual bool StartExchange() = 0;
 };
 }  //  namespace policy
 
index e180a69..a2b31a8 100644 (file)
@@ -80,7 +80,6 @@ class ResumeCtrl: public event_engine::EventObserver {
     /**
      * @brief Save application persistent info for future resuming
      * @param application is application witch need to be saved
-     * In case of IGN_OFF or Ctl-C or MEATER_RESSET this info will save to to file system
      */
     void SaveApplication(ApplicationConstSharedPtr application);
 
@@ -113,7 +112,7 @@ class ResumeCtrl: public event_engine::EventObserver {
     bool RemoveApplicationFromSaved(ApplicationConstSharedPtr application);
 
     /**
-     * @brief Save application info to FileSystem
+     * @brief Increments ignition counter for all registered applications
      */
     void IgnitionOff();
 
index 6584d3d..204b297 100644 (file)
@@ -116,6 +116,7 @@ const char initial_prompt[] = "initialPrompt";
 const char initial_text[] = "initialText";
 const char duration[] = "duration";
 const char progress_indicator[] = "progressIndicator";
+const char alert_type[] = "alertType";
 const char play_tone[] = "playTone";
 const char soft_buttons[] = "softButtons";
 const char custom_presets[] = "customPresets";
@@ -179,6 +180,7 @@ const char device_info[] = "deviceInfo";
 const char name[] = "name";
 const char id[] = "id";
 const char application[] = "application";
+const char applications[] = "applications";
 const char icon[] = "icon";
 const char device_name[] = "deviceName";
 const char reason[] = "reason";
@@ -267,6 +269,7 @@ const char alert_strings[] = "alertStrings";
 const char duration[] = "duration";
 const char soft_buttons[] = "softButtons";
 const char tts_chunks[] = "ttsChunks";
+const char speak_type[] = "speakType";
 const char audio_pass_display_texts[] = "audioPassThruDisplayTexts";
 const char max_duration[] = "maxDuration";
 const char reason[] = "reason";
index c36f956..ee878c6 100644 (file)
@@ -81,7 +81,11 @@ ApplicationManagerImpl::ApplicationManagerImpl()
     hmi_capabilities_(this),
     unregister_reason_(mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF),
     media_manager_(NULL),
-    resume_ctrl_(this) {
+    resume_ctrl_(this)
+#ifdef TIME_TESTER
+    , metric_observer_(NULL)
+#endif  // TIME_TESTER
+{
   LOG4CXX_INFO(logger_, "Creating ApplicationManager");
   media_manager_ = media_manager::MediaManagerImpl::instance();
   CreatePoliciesManager();
@@ -264,6 +268,7 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication(
   if (connection_handler_) {
     connection_handler::ConnectionHandlerImpl* con_handler_impl =
       static_cast<connection_handler::ConnectionHandlerImpl*>(
+
         connection_handler_);
     if (con_handler_impl->GetDataOnSessionKey(connection_key, &app_id,
         &sessions_list, &device_id)
@@ -357,9 +362,15 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication(
   application->set_version(version);
 
   application->set_mobile_app_id(message[strings::msg_params][strings::app_id]);
-  application->set_protocol_version(
-    static_cast<ProtocolVersion>(
-      message[strings::params][strings::protocol_version].asInt()));
+  ProtocolVersion protocol_version = static_cast<ProtocolVersion>(
+      message[strings::params][strings::protocol_version].asInt());
+  application->set_protocol_version(protocol_version);
+
+  if (ProtocolVersion::kV3 == protocol_version) {
+    if (connection_handler_) {
+      connection_handler_->StartSessionHeartBeat(connection_key);
+    }
+  }
 
   sync_primitives::AutoLock lock(applications_list_lock_);
 
@@ -590,10 +601,10 @@ void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key,
     int32_t correlation_id, int32_t max_duration, int32_t sampling_rate,
     int32_t bits_per_sample, int32_t audio_type) {
   LOG4CXX_INFO(logger_, "START MICROPHONE RECORDER");
-  if (NULL != media_manager_) {
+  if (NULL != media_manager_) {    
     media_manager_->StartMicrophoneRecording(
       session_key,
-      std::string("record.wav"),
+      profile::Profile::instance()->recording_file_name(),
       max_duration);
   }
 }
@@ -603,16 +614,11 @@ void ApplicationManagerImpl::SendAudioPassThroughNotification(
   std::vector<uint8_t> binaryData) {
   LOG4CXX_TRACE_ENTER(logger_);
 
-  {
-    sync_primitives::AutoLock lock(audio_pass_thru_lock_);
-    if (!audio_pass_thru_active_) {
-      LOG4CXX_ERROR(logger_, "Trying to send PassThroughNotification"
-                    " when PassThrough is not active");
-
-      return;
-    }
+  if (!audio_pass_thru_active_) {
+    LOG4CXX_ERROR(logger_, "Trying to send PassThroughNotification"
+                  " when PassThrough is not active");
+    return;
   }
-
   smart_objects::SmartObject* on_audio_pass = NULL;
   on_audio_pass = new smart_objects::SmartObject();
 
@@ -660,12 +666,11 @@ std::string ApplicationManagerImpl::GetDeviceName(
   DCHECK(connection_handler_ != 0);
 
   std::string device_name = "";
-  std::list<uint32_t> applications_list;
   connection_handler::ConnectionHandlerImpl* con_handler_impl =
     static_cast<connection_handler::ConnectionHandlerImpl*>(
       connection_handler_);
   if (con_handler_impl->GetDataOnDeviceID(handle, &device_name,
-                                          &applications_list) == -1) {
+                                          NULL) == -1) {
     LOG4CXX_ERROR(logger_, "Failed to extract device name for id " << handle);
   } else {
     LOG4CXX_INFO(logger_, "\t\t\t\t\tDevice name is " << device_name);
@@ -741,8 +746,57 @@ void ApplicationManagerImpl::OnDeviceListUpdated(
   ManageHMICommand(update_list);
 }
 
+void ApplicationManagerImpl::OnApplicationListUpdated(
+    const connection_handler::DeviceHandle& device_handle) {
+  LOG4CXX_INFO(logger_, "OnApplicationListUpdated. device_handle" << device_handle);
+  DCHECK(connection_handler_ != 0);
+
+  std::string device_name = "";
+  std::list<uint32_t> applications_ids;
+  connection_handler::ConnectionHandlerImpl* con_handler_impl =
+    static_cast<connection_handler::ConnectionHandlerImpl*>(
+      connection_handler_);
+  if (con_handler_impl->GetDataOnDeviceID(device_handle, &device_name,
+                                          &applications_ids) == -1) {
+    LOG4CXX_ERROR(logger_, "Failed to extract device list for id " << device_handle);
+    return;
+  }
+
+  smart_objects::SmartObject* request = MessageHelper::CreateModuleInfoSO(
+                                          hmi_apis::FunctionID::BasicCommunication_UpdateAppList);
+  (*request)[strings::msg_params][strings::applications] =
+      smart_objects::SmartObject(smart_objects::SmartType_Array);
+
+  smart_objects::SmartObject& applications =
+      (*request)[strings::msg_params][strings::applications];
+
+  uint32_t app_count = 0;
+  for (std::list<uint32_t>::iterator it = applications_ids.begin();
+       it != applications_ids.end(); ++it) {
+    ApplicationSharedPtr app = application(*it);
+
+    if (!app.valid()) {
+      LOG4CXX_ERROR(logger_, "application not foud , id = " << *it);
+      continue;
+    }
+
+    smart_objects::SmartObject hmi_application(smart_objects::SmartType_Map);;
+    if (false == MessageHelper::CreateHMIApplicationStruct(app, hmi_application)) {
+      LOG4CXX_ERROR(logger_, "can't CreateHMIApplicationStruct ', id = " << *it);
+      continue;
+    }
+    applications[app_count++] = hmi_application;
+  }
+  if (app_count > 0) {
+    ManageHMICommand(request);
+  } else {
+    LOG4CXX_WARN(logger_, "Empty applications list");
+  }
+}
+
 void ApplicationManagerImpl::RemoveDevice(
-  const connection_handler::DeviceHandle& device_handle) {
+    const connection_handler::DeviceHandle& device_handle) {
+  LOG4CXX_INFO(logger_, "device_handle " << device_handle);
 }
 
 bool ApplicationManagerImpl::IsAudioStreamingAllowed(uint32_t connection_key) const {
@@ -795,22 +849,40 @@ uint32_t ApplicationManagerImpl::GenerateNewHMIAppID() {
 }
 
 void ApplicationManagerImpl::ReplaceMobileByHMIAppId(
-  smart_objects::SmartObject& message) {
-
+    smart_objects::SmartObject& message) {
+  MessageHelper::PrintSmartObject(message);
+  flush(std::cout);
   if (message.keyExists(strings::app_id)) {
     ApplicationSharedPtr application =
-      ApplicationManagerImpl::instance()->application(
-        message[strings::app_id].asUInt());
+        ApplicationManagerImpl::instance()->application(
+          message[strings::app_id].asUInt());
     if (application.valid()) {
       LOG4CXX_INFO(logger_, "ReplaceMobileByHMIAppId from " << message[strings::app_id].asInt()
                    << " to " << application->hmi_app_id());
       message[strings::app_id] = application->hmi_app_id();
     }
   } else {
-    std::set<std::string> keys = message.enumerate();
-    std::set<std::string>::const_iterator key = keys.begin();
-    for (; key != keys.end(); ++key) {
-      ReplaceMobileByHMIAppId(message[*key]);
+    switch (message.getType()) {
+      case smart_objects::SmartType::SmartType_Array: {
+        smart_objects::SmartArray* message_array = message.asArray();
+        smart_objects::SmartArray::iterator it = message_array->begin();
+        for(; it != message_array->end(); ++it) {
+          ReplaceMobileByHMIAppId(*it);
+        }
+        break;
+      }
+      case smart_objects::SmartType::SmartType_Map: {
+        std::set<std::string> keys = message.enumerate();
+        std::set<std::string>::const_iterator key = keys.begin();
+        for (; key != keys.end(); ++key) {
+          std::string k = *key;
+          ReplaceMobileByHMIAppId(message[*key]);
+        }
+        break;
+      }
+      default: {
+        break;
+      }
     }
   }
 }
@@ -828,10 +900,26 @@ void ApplicationManagerImpl::ReplaceHMIByMobileAppId(
       message[strings::app_id] = application->app_id();
     }
   } else {
-    std::set<std::string> keys = message.enumerate();
-    std::set<std::string>::const_iterator key = keys.begin();
-    for (; key != keys.end(); ++key) {
-      ReplaceHMIByMobileAppId(message[*key]);
+    switch (message.getType()) {
+      case smart_objects::SmartType::SmartType_Array: {
+        smart_objects::SmartArray* message_array = message.asArray();
+        smart_objects::SmartArray::iterator it = message_array->begin();
+        for(; it != message_array->end(); ++it) {
+          ReplaceHMIByMobileAppId(*it);
+        }
+        break;
+      }
+      case smart_objects::SmartType::SmartType_Map: {
+        std::set<std::string> keys = message.enumerate();
+        std::set<std::string>::const_iterator key = keys.begin();
+        for (; key != keys.end(); ++key) {
+          ReplaceHMIByMobileAppId(message[*key]);
+        }
+        break;
+      }
+      default: {
+        break;
+      }
     }
   }
 }
@@ -842,7 +930,6 @@ bool ApplicationManagerImpl::OnServiceStartedCallback(
   const protocol_handler::ServiceType& type) {
   LOG4CXX_INFO(logger_,
                "OnServiceStartedCallback " << type << " in session " << session_key);
-
   ApplicationSharedPtr app = application(session_key);
 
   switch (type) {
@@ -899,7 +986,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback(const int32_t& session_key,
     case protocol_handler::kRpc: {
       LOG4CXX_INFO(logger_, "Remove application.");
       UnregisterApplication(session_key, mobile_apis::Result::INVALID_ENUM,
-                            true);
+                            false);
       break;
     }
     case protocol_handler::kMobileNav: {
@@ -932,6 +1019,11 @@ void ApplicationManagerImpl::set_connection_handler(
   connection_handler_ = handler;
 }
 
+connection_handler::ConnectionHandler*
+ApplicationManagerImpl::connection_handler() {
+  return connection_handler_;
+}
+
 void ApplicationManagerImpl::set_protocol_handler(
   protocol_handler::ProtocolHandler* handler) {
   protocol_handler_ = handler;
@@ -1156,7 +1248,7 @@ bool ApplicationManagerImpl::ManageMobileCommand(
 
         UnregisterApplication(connection_key,
                               mobile_apis::Result::TOO_MANY_PENDING_REQUESTS,
-                              true);
+                              false);
         return false;
       } else if (result ==
                  request_controller::RequestController::
@@ -1169,7 +1261,7 @@ bool ApplicationManagerImpl::ManageMobileCommand(
           REQUEST_WHILE_IN_NONE_HMI_LEVEL);
 
         UnregisterApplication(connection_key, mobile_apis::Result::INVALID_ENUM,
-                              true);
+                              false);
         return false;
       } else {
         LOG4CXX_ERROR_EXT(logger_, "Unable to perform request: Unknown case");
@@ -1530,8 +1622,10 @@ utils::SharedPtr<Message> ApplicationManagerImpl::ConvertRawMsgToMessage(
 void ApplicationManagerImpl::ProcessMessageFromMobile(
   const utils::SharedPtr<Message>& message) {
   LOG4CXX_INFO(logger_, "ApplicationManagerImpl::ProcessMessageFromMobile()");
+#ifdef TIME_TESTER
   AMMetricObserver::MessageMetricSharedPtr metric(new AMMetricObserver::MessageMetric());
   metric->begin = date_time::DateTime::getCurrentTime();
+#endif  // TIME_TESTER
   utils::SharedPtr<smart_objects::SmartObject> so_from_mobile(
     new smart_objects::SmartObject);
 
@@ -1544,15 +1638,19 @@ void ApplicationManagerImpl::ProcessMessageFromMobile(
     LOG4CXX_ERROR(logger_, "Cannot create smart object from message");
     return;
   }
+#ifdef TIME_TESTER
   metric->message = so_from_mobile;
+#endif  // TIME_TESTER
 
   if (!ManageMobileCommand(so_from_mobile)) {
     LOG4CXX_ERROR(logger_, "Received command didn't run successfully");
   }
+#ifdef TIME_TESTER
   metric->end = date_time::DateTime::getCurrentTime();
   if (metric_observer_) {
     metric_observer_->OnMessage(metric);
   }
+#endif  // TIME_TESTER
 }
 
 void ApplicationManagerImpl::ProcessMessageFromHMI(
@@ -1609,9 +1707,11 @@ HMICapabilities& ApplicationManagerImpl::hmi_capabilities() {
   return hmi_capabilities_;
 }
 
+#ifdef TIME_TESTER
 void ApplicationManagerImpl::SetTimeMetricObserver(AMMetricObserver* observer) {
   metric_observer_ = observer;
 }
+#endif  // TIME_TESTER
 
 void ApplicationManagerImpl::addNotification(const CommandSharedPtr& ptr) {
   notification_list_.push_back(ptr);
@@ -1663,10 +1763,10 @@ void ApplicationManagerImpl::HeadUnitReset(
   mobile_api::AppInterfaceUnregisteredReason::eType reason) {
   switch (reason) {
     case mobile_api::AppInterfaceUnregisteredReason::MASTER_RESET:
-      policy::PolicyHandler::instance()->InitPolicyTable();
+      policy::PolicyHandler::instance()->ResetPolicyTable();
       break;
     case mobile_api::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS:
-      policy::PolicyHandler::instance()->RevertPolicyTable();
+      policy::PolicyHandler::instance()->ClearUserConsent();
       break;
   }
 }
@@ -1677,16 +1777,22 @@ void ApplicationManagerImpl::UnregisterAllApplications() {
 
   hmi_cooperating_ = false;
 
+  bool is_ignition_off =
+      unregister_reason_ ==
+      mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF ? true : false;
+
   std::set<ApplicationSharedPtr>::iterator it = application_list_.begin();
   while (it != application_list_.end()) {
     MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
       (*it)->app_id(), unregister_reason_);
 
     UnregisterApplication((*it)->app_id(), mobile_apis::Result::INVALID_ENUM,
-                          true);
-    it = application_list_.begin();
+                          is_ignition_off);
+    it = application_list_.begin();    
+  }
+  if (is_ignition_off) {
+   resume_controller().IgnitionOff();
   }
-  resume_controller().IgnitionOff();
 }
 
 void ApplicationManagerImpl::UnregisterApplication(
index fc31b34..588b042 100644 (file)
@@ -50,17 +50,19 @@ void ActivateAppResponse::Run() {
           (*message_)[strings::params][hmi_response::code].asInt());
   if (hmi_apis::Common_Result::SUCCESS == code) {
     int32_t correlation_id = ResponseFromHMI::correlation_id();
-    const uint32_t app_id = ApplicationManagerImpl::instance()->
+    // Mobile id is converted to HMI id for HMI requests
+    const uint32_t hmi_app_id = ApplicationManagerImpl::instance()->
         application_id(correlation_id);
-    if (!app_id) {
-      LOG4CXX_ERROR(logger_, "Error app_id = "<<app_id);
+    if (!hmi_app_id) {
+      LOG4CXX_ERROR(logger_, "Error hmi_app_id = "<< hmi_app_id);
       return;
     }
-    ApplicationSharedPtr application = ApplicationManagerImpl::instance()->application(app_id);
+    ApplicationSharedPtr application = ApplicationManagerImpl::instance()->
+                                       application_by_hmi_app(hmi_app_id);
     if (application) {
       ApplicationManagerImpl::instance()->ActivateApplication(application);
     } else {
-      LOG4CXX_ERROR(logger_, "Application cannot activate");
+      LOG4CXX_ERROR(logger_, "Application can't be activated.");
     }
   } else {
     LOG4CXX_ERROR(logger_, "Error result code"<<code);
index 3aff6a9..6cbf699 100644 (file)
@@ -35,6 +35,7 @@
 #include "application_manager/application_impl.h"
 #include "application_manager/message_helper.h"
 #include "interfaces/MOBILE_API.h"
+#include "interfaces/HMI_API.h"
 
 namespace application_manager {
 
@@ -57,6 +58,29 @@ void OnExitApplicationNotification::Run() {
     LOG4CXX_ERROR(logger_, "Application does not exist");
     return;
   }
+  hmi_apis::Common_ApplicationToNONEReason::eType reason;
+  reason = static_cast<hmi_apis::Common_ApplicationToNONEReason::eType>
+                       ((*message_)[strings::msg_params][strings::reason].asInt());
+  switch (reason) {
+#ifdef CUSTOMER_FORD
+    case hmi_apis::Common_ApplicationToNONEReason::DRIVER_DISTRACTION_VIOLATION : {
+      MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
+          app_impl->app_id(),
+          mobile_api::AppInterfaceUnregisteredReason::DRIVER_DISTRACTION_VIOLATION);
+      break;
+    }
+#endif
+    case hmi_apis::Common_ApplicationToNONEReason::USER_EXIT : {
+      MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
+          app_impl->app_id(),
+          mobile_api::AppInterfaceUnregisteredReason::USER_EXIT);
+      break;
+    }
+    default : {
+      LOG4CXX_WARN(logger_, "Bad reason");
+      break;
+    }
+  }
   app_impl->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
   app_impl->set_audio_streaming_state(mobile_apis::AudioStreamingState::NOT_AUDIBLE);
   app_impl->set_system_context(mobile_api::SystemContext::SYSCTXT_MAIN);
@@ -66,4 +90,3 @@ void OnExitApplicationNotification::Run() {
 }  // namespace commands
 
 }  // namespace application_manager
-
index 458b926..b9ee33a 100644 (file)
@@ -85,7 +85,7 @@ void OnTTSLanguageChangeNotification::Run() {
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
       ApplicationManagerImpl::instance()->UnregisterApplication(
-          app->app_id(), mobile_apis::Result::SUCCESS, true);
+          app->app_id(), mobile_apis::Result::SUCCESS, false);
     }
   }
 }
index 46dda8d..9d1589d 100644 (file)
@@ -83,7 +83,7 @@ void OnUILanguageChangeNotification::Run() {
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
       ApplicationManagerImpl::instance()->UnregisterApplication(
-          app->app_id(), mobile_apis::Result::SUCCESS, true);
+          app->app_id(), mobile_apis::Result::SUCCESS, false);
     }
   }
 }
index c18b197..b3668e2 100644 (file)
@@ -80,7 +80,7 @@ void OnVRLanguageChangeNotification::Run() {
           app->app_id(),
           mobile_api::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE);
       ApplicationManagerImpl::instance()->UnregisterApplication(
-          app->app_id(), mobile_apis::Result::SUCCESS, true);
+          app->app_id(), mobile_apis::Result::SUCCESS, false);
     }
   }
 }
index 77169d0..40422c2 100644 (file)
@@ -98,8 +98,7 @@ void AlertManeuverRequest::Run() {
 
   pending_requests_.Add(hmi_apis::FunctionID::Navigation_AlertManeuver);
   SendHMIRequest(hmi_apis::FunctionID::Navigation_AlertManeuver,
-                     &msg_params,
-                     true);
+                 &msg_params, true);
 
   if (tts_is_ok) {
     smart_objects::SmartObject msg_params = smart_objects::SmartObject(
index 0169162..455b134 100644 (file)
@@ -60,7 +60,6 @@ AlertRequest::~AlertRequest() {
 }
 
 bool AlertRequest::Init() {
-
   /* Timeout in milliseconds.
      If omitted a standard value of 10000 milliseconds is used.*/
   if ((*message_)[strings::msg_params].keyExists(strings::duration)) {
@@ -71,6 +70,14 @@ bool AlertRequest::Init() {
     default_timeout_ = def_value;
   }
 
+  // If soft buttons are present, SDL will not use watchdog for response
+  // timeout tracking.
+  if ((*message_)[strings::msg_params].keyExists(strings::soft_buttons)) {
+    LOG4CXX_INFO(logger_, "Request contains soft buttons - request timeout "
+                 "will be set to 0.");
+    default_timeout_ = 0;
+  }
+
   return true;
 }
 
@@ -85,7 +92,6 @@ void AlertRequest::Run() {
     return;
   }
 
-  awaiting_ui_alert_response_ = true;
   if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) {
     if (0 < (*message_)[strings::msg_params][strings::tts_chunks].length()) {
       awaiting_tts_speak_response_ = true;
@@ -104,8 +110,10 @@ void AlertRequest::on_event(const event_engine::Event& event) {
 
   switch (event.id()) {
     case hmi_apis::FunctionID::UI_OnResetTimeout: {
-      LOG4CXX_INFO(logger_, "Received UI_OnResetTimeout event " << awaiting_tts_speak_response_ << " "
-                   << awaiting_tts_stop_speaking_response_ << " " << awaiting_ui_alert_response_);
+      LOG4CXX_INFO(logger_, "Received UI_OnResetTimeout event "
+                   << awaiting_tts_speak_response_ << " "
+                   << awaiting_tts_stop_speaking_response_ << " "
+                   << awaiting_ui_alert_response_);
       ApplicationManagerImpl::instance()->updateRequestTimeout(
           connection_key(), correlation_id(), default_timeout());
       break;
@@ -168,7 +176,21 @@ void AlertRequest::on_event(const event_engine::Event& event) {
             response_result_)) {
       response_result_ = mobile_apis::Result::WARNINGS;
       response_info = "Unsupported phoneme type sent in a prompt";
+    } else if ((mobile_apis::Result::SUCCESS == tts_speak_response_) &&
+              ((mobile_apis::Result::INVALID_ENUM == response_result_) &&
+              (!flag_other_component_sent_))) {
+      response_result_ = mobile_apis::Result::SUCCESS;
+      response_success_ = true;
+    }
+
+    // If timeout is not set, watchdog will not track request timeout and
+    // HMI is responsible for response returning. In this case, if ABORTED will
+    // be rerurned from HMI, success should be sent to mobile.
+    if (mobile_apis::Result::ABORTED == response_result_ &&
+        0 == default_timeout_) {
+      response_success_ = true;
     }
+
     SendResponse(response_success_, response_result_,
                  response_info.empty() ? NULL : response_info.c_str(),
                  &response_params_);
@@ -218,21 +240,21 @@ void AlertRequest::SendAlertRequest(int32_t app_id) {
   int32_t index = 0;
   if ((*message_)[strings::msg_params].keyExists(strings::alert_text1)) {
     msg_params[hmi_request::alert_strings][index][hmi_request::field_name] =
-         TextFieldName::ALERT_TEXT1;
+        hmi_apis::Common_TextFieldName::alertText1;
      msg_params[hmi_request::alert_strings][index][hmi_request::field_text] =
          (*message_)[strings::msg_params][strings::alert_text1];
      index++;
   }
   if ((*message_)[strings::msg_params].keyExists(strings::alert_text2)) {
     msg_params[hmi_request::alert_strings][index][hmi_request::field_name] =
-        TextFieldName::ALERT_TEXT2;
+        hmi_apis::Common_TextFieldName::alertText2;
     msg_params[hmi_request::alert_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::alert_text2];
     index++;
   }
   if ((*message_)[strings::msg_params].keyExists(strings::alert_text3)) {
     msg_params[hmi_request::alert_strings][index][hmi_request::field_name] =
-         TextFieldName::ALERT_TEXT3;
+        hmi_apis::Common_TextFieldName::alertText3;
     msg_params[hmi_request::alert_strings][index][hmi_request::field_text] =
          (*message_)[strings::msg_params][strings::alert_text3];
   }
@@ -251,11 +273,21 @@ void AlertRequest::SendAlertRequest(int32_t app_id) {
     msg_params[strings::progress_indicator] =
       (*message_)[strings::msg_params][strings::progress_indicator];
   }
+
+  // PASA Alert type
+  msg_params[strings::alert_type] = hmi_apis::Common_AlertType::UI;
+  if (awaiting_tts_speak_response_) {
+    msg_params[strings::alert_type] = hmi_apis::Common_AlertType::BOTH;
+  }
+
+  // check out if there are alert strings or soft buttons
   if (msg_params[hmi_request::alert_strings].length() > 0 ||
       msg_params.keyExists(hmi_request::soft_buttons)) {
+
+    awaiting_ui_alert_response_ = true;
     flag_other_component_sent_ = true;
+    SendHMIRequest(hmi_apis::FunctionID::UI_Alert, &msg_params, true);
   }
-  SendHMIRequest(hmi_apis::FunctionID::UI_Alert, &msg_params, true);
 }
 
 void AlertRequest::SendSpeakRequest(int32_t app_id) {
@@ -269,6 +301,8 @@ void AlertRequest::SendSpeakRequest(int32_t app_id) {
   msg_params[hmi_request::tts_chunks] =
     (*message_)[strings::msg_params][strings::tts_chunks];
   msg_params[strings::app_id] = app_id;
+  msg_params[hmi_request::speak_type] =
+      hmi_apis::Common_SpeakType::ALERT;
   SendHMIRequest(hmi_apis::FunctionID::TTS_Speak, &msg_params, true);
 }
 
index f0883df..3c3ee88 100644 (file)
@@ -81,7 +81,6 @@ void DeleteCommandRequest::Run() {
   msg_params[strings::cmd_id] =
       (*message_)[strings::msg_params][strings::cmd_id];
   msg_params[strings::app_id] = application->app_id();
-  msg_params[strings::grammar_id] = application->get_grammar_id();
 
   // we should specify amount of required responses in the 1st request
   uint32_t chaining_counter = 0;
@@ -102,6 +101,9 @@ void DeleteCommandRequest::Run() {
   if ((*command).keyExists(strings::vr_commands)) {
     is_vr_send_ = true;
 
+    // VR params
+    msg_params[strings::grammar_id] = application->get_grammar_id();
+    msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;
     SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params, true);
   }
 }
index 01c903d..7babdca 100644 (file)
@@ -123,6 +123,7 @@ void DeleteInteractionChoiceSetRequest::SendVrDeleteCommand(
     smart_objects::SmartObject msg_params = smart_objects::SmartObject(
         smart_objects::SmartType_Map);
     msg_params[strings::app_id] = app->app_id();
+    msg_params[strings::type] = hmi_apis::Common_VRCommandType::Choice;
     msg_params[strings::grammar_id] = (*choice_set)[strings::grammar_id];
     choice_set = &((*choice_set)[strings::choice_set]);
     for (uint32_t i = 0; i < (*choice_set).length() ; ++i) {
index 0617dd9..d91e742 100644 (file)
@@ -95,6 +95,8 @@ void DeleteSubMenuRequest::DeleteSubMenuVRCommands(ApplicationConstSharedPtr app
           smart_objects::SmartType_Map);
       msg_params[strings::cmd_id] = (*it->second)[strings::cmd_id].asInt();
       msg_params[strings::app_id] = app->app_id();
+      msg_params[strings::grammar_id] = app->get_grammar_id();
+      msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;
 
       SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params);
     }
index 162d1cd..822a99c 100644 (file)
@@ -50,8 +50,23 @@ DiagnosticMessageRequest::~DiagnosticMessageRequest() {
 void DiagnosticMessageRequest::Run() {
   LOG4CXX_INFO(logger_, "DiagnosticMessageRequest::Run");
 
+  uint32_t app_id = (*message_)[strings::params][strings::connection_key]
+      .asUInt();
+  ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(
+                               app_id);
+
+  if (!app) {
+    LOG4CXX_ERROR_EXT(logger_, "An application is not registered.");
+    SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED);
+    return;
+  }
+
+  // Add app_id for HMI request
+  (*message_)[strings::msg_params][strings::app_id] = app->app_id();
+
   SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage,
-                 &(*message_), true);
+                 &(*message_)[strings::msg_params], true);
+
 }
 
 void DiagnosticMessageRequest::on_event(const event_engine::Event& event) {
index ccf4ab2..a2ae783 100644 (file)
@@ -176,7 +176,7 @@ void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() {
   if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text1)) {
     msg_params[hmi_request::audio_pass_display_texts]
                [0][hmi_request::field_name] = static_cast<int32_t>
-    (application_manager::TextFieldName::AUDIO_DISPLAY_TEXT1);
+    (hmi_apis::Common_TextFieldName::audioPassThruDisplayText1);
     msg_params[hmi_request::audio_pass_display_texts]
                [0][hmi_request::field_text] =
         (*message_)[str::msg_params][str::audio_pass_display_text1];
@@ -185,7 +185,7 @@ void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() {
   if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text2)) {
     msg_params[hmi_request::audio_pass_display_texts]
                [1][hmi_request::field_name] = static_cast<int32_t>
-    (application_manager::TextFieldName::AUDIO_DISPLAY_TEXT2);
+    (hmi_apis::Common_TextFieldName::audioPassThruDisplayText2);
     msg_params[hmi_request::audio_pass_display_texts]
                [1][hmi_request::field_text] =
         (*message_)[str::msg_params][str::audio_pass_display_text2];
index f9ddc0f..2de3264 100644 (file)
@@ -406,8 +406,8 @@ void PerformInteractionRequest::SendUIPerformInteractionRequest(
 
   if (mobile_apis::InteractionMode::VR_ONLY != mode) {
     msg_params[hmi_request::initial_text][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::
-                         INITIAL_INTERACTION_TEXT);
+        static_cast<int32_t>(
+            hmi_apis::Common_TextFieldName::initialInteractionText);
     msg_params[hmi_request::initial_text][hmi_request::field_text] =
         (*message_)[strings::msg_params][hmi_request::initial_text];
   }
index 00a70b2..5626ce4 100644 (file)
@@ -104,7 +104,7 @@ void PutFileRequest::Run() {
                  &response_params);
     return;
   }
-
+  smart_objects::SmartType t = (*message_)[strings::msg_params][strings::system_file].getType();
   sync_file_name_ =
     (*message_)[strings::msg_params][strings::sync_file_name].asString();
   file_type_ =
index fcdf630..a344d77 100644 (file)
@@ -604,8 +604,14 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckWithPolicyData() {
     policy::PolicyHandler::instance()->policy_manager();
   if (!policy_manager) {
     LOG4CXX_WARN(logger_, "The shared library of policy is not loaded");
+    // TODO(AOleynik): Check is necessary to allow register application in case
+    // of disabled policy
+    // Remove this check, when HMI will support policy
+    if (profile::Profile::instance()->policy_turn_off()) {
     return mobile_apis::Result::WARNINGS;
   }
+    return mobile_apis::Result::DISALLOWED;
+  }
   const bool init_result = policy_manager->GetInitialAppData(
                              message[strings::msg_params][strings::app_id].asString(), &app_nicknames,
                              &app_hmi_types);
@@ -767,10 +773,11 @@ RegisterAppInterfaceRequest::ClearParamName(std::string param_name) const {
 
 bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() {
 
-  LOG4CXX_INFO(logger_, "RegisterAppInterfaceRequest::IsApplicationRegistered");
+  LOG4CXX_INFO(logger_, "RegisterAppInterfaceRequest::"
+               "IsApplicationWithSameAppIdRegistered");
 
-  int32_t mobile_app_id = (*message_)[strings::msg_params][strings::app_id]
-                          .asInt();
+  const std::string mobile_app_id = (*message_)[strings::msg_params]
+                                    [strings::app_id].asString();
 
   const std::set<ApplicationSharedPtr>& applications =
     ApplicationManagerImpl::instance()->applications();
@@ -779,7 +786,7 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() {
   std::set<ApplicationSharedPtr>::const_iterator it_end = applications.end();
 
   for (; it != it_end; ++it) {
-    if (mobile_app_id == (*it)->mobile_app_id()->asInt()) {
+    if (mobile_app_id == (*it)->mobile_app_id()->asString()) {
       return true;
     }
   }
index fb82e05..0f01430 100644 (file)
@@ -56,8 +56,23 @@ void RegisterAppInterfaceResponse::Run() {
     }
   }
 
+
+  bool close_session = false;
+  if (last_message) {
+    if (1 < ApplicationManagerImpl::instance()->connection_handler()->GetConnectionSessionsCount(
+        (*message_)[strings::params][strings::connection_key].asUInt())) {
+      last_message = false;
+      close_session = true;
+    }
+  }
+
   SendResponse(success, mobile_apis::Result::INVALID_ENUM, last_message);
 
+  if (close_session) {
+    ApplicationManagerImpl::instance()->connection_handler()->CloseSession(
+        (*message_)[strings::params][strings::connection_key].asUInt());
+  }
+
   if (success) {
     ApplicationSharedPtr application =
         ApplicationManagerImpl::instance()->application(
index 2c403e0..083376e 100644 (file)
@@ -91,7 +91,7 @@ void ScrollabelMessageRequest::Run() {
       smart_objects::SmartType_Map);
 
   msg_params[hmi_request::message_text][hmi_request::field_name] =
-     static_cast<int32_t>(application_manager::TextFieldName::SCROLLABLE_MSG_BODY);
+    static_cast<int32_t>(hmi_apis::Common_TextFieldName::scrollableMessageBody);
   msg_params[hmi_request::message_text][hmi_request::field_text] =
       (*message_)[strings::msg_params][strings::scroll_message_body];
   msg_params[strings::app_id] = app->app_id();
index 6f56dd2..0525572 100644 (file)
@@ -114,7 +114,7 @@ void ShowConstantTBTRequest::Run() {
     // erase useless parametr
     msg_params.erase(strings::navigation_text_1);
     msg_params[hmi_request::navi_texts][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::NAVI_TEXT1);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::navigationText1);
     msg_params[hmi_request::navi_texts][index++][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::navigation_text_1];
   }
@@ -123,7 +123,7 @@ void ShowConstantTBTRequest::Run() {
     // erase useless param
     msg_params.erase(strings::navigation_text_2);
     msg_params[hmi_request::navi_texts][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::NAVI_TEXT2);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::navigationText2);
     msg_params[hmi_request::navi_texts][index++][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::navigation_text_2];
   }
@@ -132,7 +132,7 @@ void ShowConstantTBTRequest::Run() {
     // erase useless param
     msg_params.erase(strings::eta);
     msg_params[hmi_request::navi_texts][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::ETA);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::ETA);
     msg_params[hmi_request::navi_texts][index++][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::eta];
   }
@@ -141,7 +141,7 @@ void ShowConstantTBTRequest::Run() {
     // erase useless param
     msg_params.erase(strings::total_distance);
     msg_params[hmi_request::navi_texts][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::TOTAL_DISTANCE);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::totalDistance);
     msg_params[hmi_request::navi_texts][index++][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::total_distance];
   }
index 9422e31..40e57e8 100644 (file)
@@ -113,7 +113,7 @@ void ShowRequest::Run() {
   int32_t index = 0;
   if ((*message_)[strings::msg_params].keyExists(strings::main_field_1)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MAIN_FILED1);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mainField1);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::main_field_1];
     ++index;
@@ -121,7 +121,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::main_field_2)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MAIN_FILED2);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mainField2);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::main_field_2];
     ++index;
@@ -129,7 +129,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::main_field_3)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MAIN_FILED3);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mainField3);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::main_field_3];
     ++index;
@@ -137,7 +137,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::main_field_4)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MAIN_FILED4);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mainField4);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::main_field_4];
     ++index;
@@ -145,7 +145,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::media_clock)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MEDIA_CLOCK);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mediaClock);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::media_clock];
     ++index;
@@ -153,7 +153,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::media_track)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::MEDIA_TRACK);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::mediaTrack);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::media_track];
     ++index;
@@ -161,7 +161,7 @@ void ShowRequest::Run() {
 
   if ((*message_)[strings::msg_params].keyExists(strings::status_bar)) {
     msg_params[hmi_request::show_strings][index][hmi_request::field_name] =
-        static_cast<int32_t>(application_manager::TextFieldName::STATUS_BAR);
+        static_cast<int32_t>(hmi_apis::Common_TextFieldName::statusBar);
     msg_params[hmi_request::show_strings][index][hmi_request::field_text] =
         (*message_)[strings::msg_params][strings::status_bar];
     ++index;
index 05e4b23..0f0064b 100644 (file)
@@ -59,6 +59,8 @@ void SpeakRequest::Run() {
   }
 
   (*message_)[strings::msg_params][strings::app_id] = app->app_id();
+  (*message_)[strings::msg_params][hmi_request::speak_type] =
+      hmi_apis::Common_SpeakType::SPEAK;
   SendHMIRequest(hmi_apis::FunctionID::TTS_Speak,
                  &message_->getElement(strings::msg_params), true);
 }
index 4044212..23491e4 100644 (file)
@@ -572,9 +572,6 @@ smart_objects::SmartObject* MessageHelper::CreateModuleInfoSO(
   uint32_t function_id) {
   smart_objects::SmartObject* module_info = new smart_objects::SmartObject(
     smart_objects::SmartType_Map);
-  if (NULL == module_info) {
-    return NULL;
-  }
   smart_objects::SmartObject& object = *module_info;
   object[strings::params][strings::message_type] = static_cast<int>(kRequest);
   object[strings::params][strings::function_id] = static_cast<int>(function_id);
@@ -1095,6 +1092,35 @@ smart_objects::SmartObject* MessageHelper::CreateAddVRCommandToHMI(
   return vr_command;
 }
 
+bool MessageHelper::CreateHMIApplicationStruct(ApplicationConstSharedPtr app,
+                                               smart_objects::SmartObject& output) {
+
+  if (false == app.valid()) {
+    return false;
+  }
+
+  const smart_objects::SmartObject* app_types = app->app_types();
+  const smart_objects::SmartObject* ngn_media_screen_name = app->ngn_media_screen_name();
+  const connection_handler::DeviceHandle handle = app->device();
+  std::string device_name = ApplicationManagerImpl::instance()->GetDeviceName(handle);
+
+  output = smart_objects::SmartObject(smart_objects::SmartType_Map);
+  output[strings::app_name] = app->name();
+  output[strings::icon] = app->app_icon_path();
+  output[strings::device_name] = device_name;
+  output[strings::app_id] = app->app_id();
+  output[strings::hmi_display_language_desired] = app->ui_language();
+  output[strings::is_media_application] = app->is_media_application();
+
+  if (NULL != ngn_media_screen_name) {
+    output[strings::ngn_media_screen_app_name] = ngn_media_screen_name;
+  }
+  if (NULL != app_types) {
+    output[strings::app_type] = *app_types;
+  }
+  return true;
+}
+
 void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app) {
   DCHECK(app.get());
   SmartObjectList requests = CreateAddSubMenuRequestToHMI(app);
@@ -1177,7 +1203,8 @@ void MessageHelper::SendOnAppUnregNotificationToHMI(
   ApplicationManagerImpl::instance()->ManageHMICommand(&message);
 }
 
-void MessageHelper::SendActivateAppToHMI(uint32_t const app_id) {
+void MessageHelper::SendActivateAppToHMI(uint32_t const app_id,
+    hmi_apis::Common_HMILevel::eType level) {
   smart_objects::SmartObject* message = new smart_objects::SmartObject(
     smart_objects::SmartType_Map);
 
@@ -1209,6 +1236,11 @@ void MessageHelper::SendActivateAppToHMI(uint32_t const app_id) {
     (*message)[strings::msg_params]["priority"] = GetPriorityCode(priority);
   }
 
+  if (hmi_apis::Common_HMILevel::FULL != level &&
+      hmi_apis::Common_HMILevel::INVALID_ENUM != level) {
+    (*message)[strings::msg_params]["level"] = level;
+  }
+
   ApplicationManagerImpl::instance()->ManageHMICommand(message);
 }
 
index f602e80..00d05da 100644 (file)
 #include "utils/macro.h"
 #include "utils/date_time.h"
 #include "json/value.h"
+#include "json/writer.h"
 #include "config_profile/profile.h"
 #include "application_manager/usage_statistics.h"
 #include "policy/policy_types.h"
+#include "interfaces/MOBILE_API.h"
 
 namespace policy {
 typedef std::set<utils::SharedPtr<application_manager::Application>> ApplicationList;
@@ -61,7 +63,6 @@ PolicyHandler::PolicyHandler()
   : policy_manager_(0),
     dl_handle_(0),
     exchange_handler_(NULL),
-    is_exchange_in_progress_(false),
     on_ignition_check_done_(false),
     retry_sequence_("RetrySequence", new RetrySequence(this)) {
 }
@@ -108,22 +109,34 @@ PolicyManager* PolicyHandler::CreateManager() {
 }
 
 bool PolicyHandler::InitPolicyTable() {
+  LOG4CXX_TRACE(logger_, "Init policy table.");
+  if (!policy_manager_) {
+    LOG4CXX_WARN(logger_, "The shared library of policy is not loaded");
+    return false;
+  }
   std::string preloaded_file =
-    profile::Profile::instance()->preloaded_pt_file();
+      profile::Profile::instance()->preloaded_pt_file();
+  return policy_manager_->InitPT(preloaded_file);
+}
+
+bool PolicyHandler::ResetPolicyTable() {
+  LOG4CXX_TRACE(logger_, "Reset policy table.");
   if (!policy_manager_) {
     LOG4CXX_WARN(logger_, "The shared library of policy is not loaded");
     return false;
   }
-  return policy_manager_->LoadPTFromFile(preloaded_file);
+  std::string preloaded_file =
+      profile::Profile::instance()->preloaded_pt_file();
+  return policy_manager_->ResetPT(preloaded_file);
 }
 
-bool PolicyHandler::RevertPolicyTable() {
+bool PolicyHandler::ClearUserConsent() {
   LOG4CXX_INFO(logger_, "Removing user consent records in policy table.");
   if (!policy_manager_) {
     LOG4CXX_WARN(logger_, "The shared library of policy is not loaded");
     return false;
   }
-  return policy_manager()->ResetUserConsent();
+  return policy_manager_->ResetUserConsent();
 }
 
 uint32_t PolicyHandler::GetAppIdForSending() {
@@ -301,9 +314,9 @@ void PolicyHandler::OnGetListOfPermissions(const uint32_t connection_key,
   } else if (!app) {
     LOG4CXX_WARN(logger_, "Couldn't find application to get permissions.");
   } else {
-    policy_manager_->GetUserPermissionsForApp(device_params.device_mac_address,
-        app->mobile_app_id()->asString(),
-        group_permissions);
+    policy_manager_->GetUserConsentForApp(device_params.device_mac_address,
+                                          app->mobile_app_id()->asString(),
+                                          group_permissions);
   }
 
   application_manager::MessageHelper::SendGetListOfPermissionsResponse(
@@ -392,6 +405,10 @@ void PolicyHandler::OnAppRevoked(const std::string& policy_app_id) {
       app->app_id(), permissions);
     application_manager::ApplicationManagerImpl::instance()
     ->DeactivateApplication(app);
+    application_manager::MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile(
+        app->app_id(), mobile_apis::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED);
+    application_manager::ApplicationManagerImpl::instance()->
+        UnregisterApplication(app->app_id(), mobile_apis::Result::INVALID_ENUM, false);
     app->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
     policy_manager_->RemovePendingPermissionChanges(policy_app_id);
     return;
@@ -433,13 +450,37 @@ void PolicyHandler::OnPendingPermissionChange(
   }
 }
 
+BinaryMessageSptr PolicyHandler::AddHttpHeader(const BinaryMessageSptr& pt_string) {
+  Json::Value packet(Json::objectValue);
+  packet["HTTPRequest"] = Json::Value(Json::objectValue);
+  packet["HTTPRequest"]["headers"] = Json::Value(Json::objectValue);
+  packet["HTTPRequest"]["headers"]["ContentType"] = Json::Value("application/json");
+  packet["HTTPRequest"]["headers"]["ConnectTimeout"] = Json::Value(policy_manager_->TimeoutExchange());
+  packet["HTTPRequest"]["headers"]["DoOutput"] = Json::Value(true);
+  packet["HTTPRequest"]["headers"]["DoInput"] = Json::Value(true);
+  packet["HTTPRequest"]["headers"]["UseCaches"] = Json::Value(false);
+  packet["HTTPRequest"]["headers"]["RequestMethod"] = Json::Value("POST");
+  packet["HTTPRequest"]["headers"]["ReadTimeout"] = Json::Value(policy_manager_->TimeoutExchange());
+  packet["HTTPRequest"]["headers"]["InstanceFollowRedirects"] = Json::Value(false);
+  packet["HTTPRequest"]["headers"]["charset"] = Json::Value("utf-8");
+  packet["HTTPRequest"]["headers"]["Content_Length"] = Json::Value(static_cast<int>(pt_string->size()));
+  packet["HTTPRequest"]["body"] = Json::Value(Json::objectValue);
+  packet["HTTPRequest"]["body"]["data"] = Json::Value(Json::arrayValue);
+  packet["HTTPRequest"]["body"]["data"][0] = Json::Value(std::string(pt_string->begin(),
+      pt_string->end()));
+
+  Json::FastWriter writer;
+  std::string message = writer.write(packet);
+  LOG4CXX_DEBUG(logger_, "Packet PT: " << message);
+  return new BinaryMessage(message.begin(), message.end());
+}
+
 bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string) {
   LOG4CXX_INFO(logger_, "PolicyHandler::SendMessageToSDK");
   if (!policy_manager_) {
     LOG4CXX_WARN(logger_, "The shared library of policy is not loaded");
     return false;
   }
-  is_exchange_in_progress_ = true;
 
   std::string url;
   uint32_t app_id = last_used_app_ids_.back();
@@ -469,6 +510,7 @@ bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string) {
   application_manager::MessageHelper::SendPolicySnapshotNotification(app_id,
       pt_string,
       url, 0);
+
   return true;
 }
 
@@ -479,7 +521,12 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
     return false;
   }
 
-  is_exchange_in_progress_ = false;
+  if (policy_manager_->GetPolicyTableStatus() !=
+      PolicyTableStatus::StatusUpdatePending) {
+    LOG4CXX_WARN(logger_,
+                 "Update policy is skipped because request to update was not");
+    return false;
+  }
 
   bool ret = policy_manager_->LoadPT(file, pt_string);
   LOG4CXX_INFO(logger_, "Policy table is saved: " << std::boolalpha << ret);
@@ -488,6 +535,7 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
     retry_sequence_lock_.Ackquire();
     retry_sequence_.stop();
     retry_sequence_lock_.Release();
+    policy_manager_->CleanupUnpairedDevices();
     int32_t correlation_id =
       application_manager::ApplicationManagerImpl::instance()
       ->GetNextHMICorrelationID();
@@ -503,9 +551,6 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
     std::vector<std::string> vehicle_data_args;
     vehicle_data_args.push_back(application_manager::strings::odometer);
     application_manager::MessageHelper::CreateGetVehicleDataRequest(correlation_id, vehicle_data_args);
-    if (policy_manager_->CleanupUnpairedDevices(unpaired_device_ids_)) {
-      unpaired_device_ids_.clear();
-    }
   } else  {
     // TODO(PV): should be exchange restarted at this point?
     LOG4CXX_WARN(logger_, "Exchange wasn't successful, trying another one.");
@@ -532,7 +577,8 @@ void PolicyHandler::StartPTExchange(bool skip_device_selection) {
     return;
   }
 
-  if (is_exchange_in_progress_) {
+  if (policy_manager_->GetPolicyTableStatus() ==
+      PolicyTableStatus::StatusUpdatePending) {
     LOG4CXX_INFO(logger_, "Starting exchange skipped, since another exchange "
                  "is in progress.");
     return;
@@ -670,7 +716,10 @@ void PolicyHandler::OnActivateApp(uint32_t connection_key,
 
     usage.RecordAppUserSelection();
 
-    DeviceConsent consent = GetDeviceForSending(permissions.deviceInfo);
+    application_manager::MessageHelper::GetDeviceInfoForApp(connection_key,
+        &permissions.deviceInfo);
+    DeviceConsent consent = policy_manager_->GetUserConsentForDevice(
+                              permissions.deviceInfo.device_mac_address);
     permissions.isSDLAllowed = kDeviceAllowed == consent ? true : false;
 
     if (permissions.appRevoked) {
@@ -882,9 +931,7 @@ void PolicyHandler::RemoveDevice(const std::string& device_id) {
     return;
   }
 
-  policy::DeviceIds devices;
-  devices.insert(device_id);
-  policy_manager_->CleanupUnpairedDevices(devices);
+  policy_manager_->MarkUnpairedDevice(device_id);
 }
 
 }  //  namespace policy
index 603674e..99eebc7 100644 (file)
@@ -68,6 +68,7 @@ bool PTExchangeHandlerExt::StartExchange() {
     Profile::instance()->policies_snapshot_file_name();
   BinaryMessageSptr pt_snapshot = policy_manager->RequestPTUpdate();
   if (pt_snapshot.valid()) {
+    pt_snapshot = policy_handler_->AddHttpHeader(pt_snapshot);
     if (file_system::WriteBinaryFile(policy_snapshot_file_name, *pt_snapshot)) {
       MessageHelper::SendPolicyUpdate(policy_snapshot_file_name,
                                       policy_manager->TimeoutExchange(),
index 433c0cd..7cb74d2 100644 (file)
@@ -105,6 +105,14 @@ RequestController::TResult RequestController::addRequest(
     } else {
 
       request_list_.push_back(request);
+      LOG4CXX_INFO(logger_, "RequestController size is " <<
+                   request_list_.size());
+
+      if (0 == request_impl->default_timeout()) {
+        LOG4CXX_INFO(logger_, "Default timeout was set to 0. Watchdog will not "
+                     "track this request.");
+        return result;
+      }
 
       LOG4CXX_INFO(logger_, "Adding request to watchdog. Default timeout is "
                    << request_impl->default_timeout());
@@ -116,8 +124,7 @@ RequestController::TResult RequestController::addRequest(
                               request_impl->default_timeout(),
                               hmi_level));
 
-      LOG4CXX_INFO(logger_, "Added request to watchdog.");
-      LOG4CXX_INFO(logger_, "RequestController size is " << request_list_.size());
+      LOG4CXX_INFO(logger_, "Added request to watchdog.");      
     }
   }