Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CloseApplication RPC #2948

Merged
merged 4 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,16 @@ class MessageHelper {
bool is_unexpected_disconnect,
ApplicationManager& app_mngr);

static ns_smart_device_link::ns_smart_objects::SmartObjectSPtr
GetBCActivateAppRequestToHMI(
static smart_objects::SmartObjectSPtr GetBCActivateAppRequestToHMI(
ApplicationConstSharedPtr app,
const protocol_handler::SessionObserver& session_observer,
const policy::PolicyHandlerInterface& policy_handler,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority,
ApplicationManager& app_mngr);

static smart_objects::SmartObjectSPtr GetBCCloseApplicationRequestToHMI(
ApplicationConstSharedPtr app, ApplicationManager& app_mngr);

static void SendOnResumeAudioSourceToHMI(const uint32_t app_id,
ApplicationManager& app_mngr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ class StateControllerImpl : public event_engine::EventObserver,
virtual bool IsStateActive(HmiState::StateID state_id) const;

private:
int64_t SendBCActivateApp(ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority);
int64_t SendStateToHMI(ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority);
/**
* @brief The HmiLevelConflictResolver struct
* Move other application to HmiStates if applied moved to FULL or LIMITED
Expand Down Expand Up @@ -378,10 +378,11 @@ class StateControllerImpl : public event_engine::EventObserver,
const mobile_apis::VideoStreamingState::eType video_state);

/**
* @brief OnActivateAppResponse calback for activate app response
* @brief OnHMIResponse callback for activate app or close application
* response
* @param message Smart Object
*/
void OnActivateAppResponse(const smart_objects::SmartObject& message);
void OnHMIResponse(const smart_objects::SmartObject& message);

/**
* @brief OnAppDeactivated callback for OnAppDeactivated notification
Expand Down Expand Up @@ -449,7 +450,7 @@ class StateControllerImpl : public event_engine::EventObserver,
typedef std::list<HmiState::StateID> StateIDList;
StateIDList active_states_;
mutable sync_primitives::Lock active_states_lock_;
std::map<uint32_t, HmiStatePtr> waiting_for_activate_;
std::map<uint32_t, HmiStatePtr> waiting_for_response_;
ApplicationManager& app_mngr_;
};
} // namespace application_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class BasicCommunicationCloseApplicationRequest
/**
* @brief BasicCommunicationCloseApplicationRequest class destructor
**/
virtual ~BasicCommunicationCloseApplicationRequest();
~BasicCommunicationCloseApplicationRequest() OVERRIDE;

/**
* @brief Execute command
**/
virtual void Run();
void Run() OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(BasicCommunicationCloseApplicationRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class BasicCommunicationCloseApplicationResponse
/**
* @brief BasicCommunicationCloseApplicationResponse class destructor
**/
virtual ~BasicCommunicationCloseApplicationResponse();
~BasicCommunicationCloseApplicationResponse() OVERRIDE;

/**
* @brief Execute command
**/
virtual void Run();
void Run() OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(BasicCommunicationCloseApplicationResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class CloseApplicationRequest : public app_mngr::commands::CommandRequestImpl {
/**
* @brief CloseApplicationRequest class destructor
**/
virtual ~CloseApplicationRequest();
~CloseApplicationRequest() OVERRIDE;

/**
* @brief Execute command
**/
virtual void Run();
void Run() OVERRIDE;

/**
* @brief Interface method that is called whenever new event received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class CloseApplicationResponse
/**
* @brief CloseApplicationResponse class destructor
**/
virtual ~CloseApplicationResponse();
~CloseApplicationResponse() OVERRIDE;

/**
* @brief Execute command
**/
virtual void Run();
void Run() OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(CloseApplicationResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1789,12 +1789,16 @@ void MessageHelper::SendOnAppUnregNotificationToHMI(

smart_objects::SmartObjectSPtr MessageHelper::GetBCActivateAppRequestToHMI(
ApplicationConstSharedPtr app,
const protocol_handler::SessionObserver& session_observer,
const policy::PolicyHandlerInterface& policy_handler,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority,
ApplicationManager& app_mngr) {
DCHECK_OR_RETURN(app, smart_objects::SmartObjectSPtr());
if (hmi_apis::Common_HMILevel::NONE == level) {
jacobkeeler marked this conversation as resolved.
Show resolved Hide resolved
LOG4CXX_WARN(logger_,
"BC.ActivateApp cannot be used to deactivate an application");
return NULL;
}

const uint32_t correlation_id = app_mngr.GetNextHMICorrelationID();
smart_objects::SmartObjectSPtr message =
Expand Down Expand Up @@ -1831,6 +1835,23 @@ smart_objects::SmartObjectSPtr MessageHelper::GetBCActivateAppRequestToHMI(
return message;
}

smart_objects::SmartObjectSPtr MessageHelper::GetBCCloseApplicationRequestToHMI(
ApplicationConstSharedPtr app, ApplicationManager& app_mngr) {
DCHECK_OR_RETURN(app, smart_objects::SmartObjectSPtr());

const uint32_t correlation_id = app_mngr.GetNextHMICorrelationID();
smart_objects::SmartObjectSPtr message =
std::make_shared<smart_objects::SmartObject>(
smart_objects::SmartType_Map);
(*message)[strings::params][strings::function_id] =
hmi_apis::FunctionID::BasicCommunication_CloseApplication;
(*message)[strings::params][strings::message_type] = MessageType::kRequest;
(*message)[strings::params][strings::correlation_id] = correlation_id;
(*message)[strings::msg_params][strings::app_id] = app->app_id();

return message;
}

void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id,
ApplicationManager& app_mngr) {
LOG4CXX_WARN(logger_, "SendOnResumeAudioSourceToHMI app_id: " << app_id);
Expand Down
35 changes: 0 additions & 35 deletions src/components/application_manager/src/policies/policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,41 +177,6 @@ struct DeactivateApplication {
StateController& state_ctrl_;
};

struct SDLAllowedNotification {
SDLAllowedNotification(const connection_handler::DeviceHandle& device_id,
PolicyManager* policy_manager,
StateController& state_controller)
: device_id_(device_id)
, policy_manager_(policy_manager)
, state_controller_(state_controller) {}

void operator()(const ApplicationSharedPtr& app) {
DCHECK_OR_RETURN_VOID(policy_manager_);
if (device_id_ == app->device()) {
std::string hmi_level = "NONE";
mobile_apis::HMILevel::eType default_mobile_hmi;
policy_manager_->GetDefaultHmi(app->policy_app_id(), &hmi_level);
if ("BACKGROUND" == hmi_level) {
default_mobile_hmi = mobile_apis::HMILevel::HMI_BACKGROUND;
} else if ("FULL" == hmi_level) {
default_mobile_hmi = mobile_apis::HMILevel::HMI_FULL;
} else if ("LIMITED" == hmi_level) {
default_mobile_hmi = mobile_apis::HMILevel::HMI_LIMITED;
} else if ("NONE" == hmi_level) {
default_mobile_hmi = mobile_apis::HMILevel::HMI_NONE;
} else {
return;
}
state_controller_.SetRegularState(app, default_mobile_hmi, true);
}
}

private:
connection_handler::DeviceHandle device_id_;
PolicyManager* policy_manager_;
StateController& state_controller_;
};

/**
* @brief Gets from system list of currently registered applications and
* create collection of links device-to-application
Expand Down
80 changes: 44 additions & 36 deletions src/components/application_manager/src/state_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ StateControllerImpl::StateControllerImpl(ApplicationManager& app_mngr)

void StateControllerImpl::SetRegularState(ApplicationSharedPtr app,
HmiStatePtr state,
const bool send_activate_app) {
const bool send_state_to_hmi) {
LOG4CXX_AUTO_TRACE(logger_);
DCHECK_OR_RETURN_VOID(app);
DCHECK_OR_RETURN_VOID(state);
Expand Down Expand Up @@ -101,12 +101,17 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app,
static_cast<hmi_apis::Common_HMILevel::eType>(
resolved_state->hmi_level());

if (send_activate_app) {
const int64_t corr_id = SendBCActivateApp(app, hmi_level, true);
if (-1 != corr_id) {
subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp,
corr_id);
waiting_for_activate_[app->app_id()] = resolved_state;
if (send_state_to_hmi) {
const int64_t result = SendStateToHMI(app, hmi_level, true);
if (-1 != result) {
const uint32_t corr_id = static_cast<uint32_t>(result);
subscribe_on_event(
hmi_apis::Common_HMILevel::NONE == hmi_level
? hmi_apis::FunctionID::BasicCommunication_CloseApplication
: hmi_apis::FunctionID::BasicCommunication_ActivateApp,
corr_id);
waiting_for_response_[app->app_id()] = resolved_state;
app_mngr_.set_application_id(corr_id, app->hmi_app_id());
return;
}
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp");
Expand All @@ -120,7 +125,7 @@ void StateControllerImpl::SetRegularState(
const mobile_apis::HMILevel::eType hmi_level,
const mobile_apis::AudioStreamingState::eType audio_state,
const mobile_apis::VideoStreamingState::eType video_state,
const bool send_activate_app) {
const bool send_state_to_hmi) {
LOG4CXX_AUTO_TRACE(logger_);
DCHECK_OR_RETURN_VOID(app);
HmiStatePtr prev_regular = app->RegularHmiState();
Expand All @@ -132,13 +137,13 @@ void StateControllerImpl::SetRegularState(
hmi_state->set_audio_streaming_state(audio_state);
hmi_state->set_video_streaming_state(video_state);
hmi_state->set_system_context(prev_regular->system_context());
SetRegularState(app, hmi_state, send_activate_app);
SetRegularState(app, hmi_state, send_state_to_hmi);
}

void StateControllerImpl::SetRegularState(
ApplicationSharedPtr app,
const mobile_apis::HMILevel::eType hmi_level,
const bool send_activate_app) {
const bool send_state_to_hmi) {
using namespace mobile_apis;
LOG4CXX_AUTO_TRACE(logger_);
DCHECK_OR_RETURN_VOID(app);
Expand All @@ -150,7 +155,7 @@ void StateControllerImpl::SetRegularState(
hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level));
hmi_state->set_video_streaming_state(CalcVideoState(app, hmi_level));
hmi_state->set_system_context(SystemContext::SYSCTXT_MAIN);
SetRegularState(app, hmi_state, send_activate_app);
SetRegularState(app, hmi_state, send_state_to_hmi);
}

void StateControllerImpl::SetRegularState(
Expand All @@ -159,7 +164,7 @@ void StateControllerImpl::SetRegularState(
const mobile_apis::AudioStreamingState::eType audio_state,
const mobile_apis::VideoStreamingState::eType video_state,
const mobile_apis::SystemContext::eType system_context,
const bool send_activate_app) {
const bool send_state_to_hmi) {
jacobkeeler marked this conversation as resolved.
Show resolved Hide resolved
LOG4CXX_AUTO_TRACE(logger_);
DCHECK_OR_RETURN_VOID(app);
HmiStatePtr hmi_state =
Expand All @@ -169,7 +174,7 @@ void StateControllerImpl::SetRegularState(
hmi_state->set_audio_streaming_state(audio_state);
hmi_state->set_video_streaming_state(video_state);
hmi_state->set_system_context(system_context);
SetRegularState(app, hmi_state, send_activate_app);
SetRegularState(app, hmi_state, send_state_to_hmi);
}

void StateControllerImpl::SetRegularState(
Expand Down Expand Up @@ -636,8 +641,9 @@ void StateControllerImpl::on_event(const event_engine::Event& event) {
const SmartObject& message = event.smart_object();
const FunctionID::eType id = static_cast<FunctionID::eType>(event.id());
switch (id) {
case FunctionID::BasicCommunication_ActivateApp: {
OnActivateAppResponse(message);
case FunctionID::BasicCommunication_ActivateApp:
case FunctionID::BasicCommunication_CloseApplication: {
OnHMIResponse(message);
break;
}
case FunctionID::BasicCommunication_OnAppActivated: {
Expand Down Expand Up @@ -791,31 +797,33 @@ void StateControllerImpl::OnApplicationRegistered(
OnStateChanged(app, initial_state, new_state);
}

int64_t StateControllerImpl::SendBCActivateApp(
int64_t StateControllerImpl::SendStateToHMI(
jacobkeeler marked this conversation as resolved.
Show resolved Hide resolved
ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority) {
LOG4CXX_AUTO_TRACE(logger_);
smart_objects::SmartObjectSPtr bc_activate_app_request =
MessageHelper::GetBCActivateAppRequestToHMI(
app,
app_mngr_.connection_handler().get_session_observer(),
app_mngr_.GetPolicyHandler(),
level,
send_policy_priority,
app_mngr_);
if (!bc_activate_app_request) {
LOG4CXX_ERROR(logger_, "Unable to create BC.ActivateAppRequest");
smart_objects::SmartObjectSPtr request = NULL;
if (level == hmi_apis::Common_HMILevel::NONE) {
jacobkeeler marked this conversation as resolved.
Show resolved Hide resolved
request = MessageHelper::GetBCCloseApplicationRequestToHMI(app, app_mngr_);
} else {
request = MessageHelper::GetBCActivateAppRequestToHMI(
app,
app_mngr_.GetPolicyHandler(),
level,
send_policy_priority,
app_mngr_);
}
if (!request) {
LOG4CXX_ERROR(logger_, "Unable to create request");
return -1;
}
if (!app_mngr_.GetRPCService().ManageHMICommand(bc_activate_app_request)) {
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateAppRequest");
if (!app_mngr_.GetRPCService().ManageHMICommand(request)) {
LOG4CXX_ERROR(logger_, "Unable to send request");
return -1;
}
const int64_t corr_id =
(*bc_activate_app_request)[strings::params][strings::correlation_id]
.asInt();
return corr_id;
const uint32_t corr_id =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to uint32 and then recast to int64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this was originally chosen for the return value of SendBCActivateApp to allow for an error response of -1, correlation IDs use uint32_t. I could remove these casts, but it was being done implicitly before anyway.

(*request)[strings::params][strings::correlation_id].asUInt();
return static_cast<int64_t>(corr_id);
}

void StateControllerImpl::ApplyPostponedStateForApp(ApplicationSharedPtr app) {
Expand Down Expand Up @@ -890,18 +898,18 @@ void StateControllerImpl::DeactivateApp(ApplicationSharedPtr app) {
SetRegularState(app, new_regular, false);
}

void StateControllerImpl::OnActivateAppResponse(
void StateControllerImpl::OnHMIResponse(
const smart_objects::SmartObject& message) {
const hmi_apis::Common_Result::eType code =
static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
const int32_t correlation_id =
message[strings::params][strings::correlation_id].asInt();
const uint32_t correlation_id =
message[strings::params][strings::correlation_id].asUInt();
const uint32_t hmi_app_id = app_mngr_.application_id(correlation_id);
ApplicationSharedPtr application =
app_mngr_.application_by_hmi_app(hmi_app_id);
if (application && hmi_apis::Common_Result::SUCCESS == code) {
HmiStatePtr pending_state = waiting_for_activate_[application->app_id()];
HmiStatePtr pending_state = waiting_for_response_[application->app_id()];
DCHECK_OR_RETURN_VOID(pending_state);
ApplyRegularState(application, pending_state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ class MockMessageHelper {
MessageHelper::ChoiceSetVRCommandsStatus(
const smart_objects::SmartObject&));

MOCK_METHOD6(GetBCActivateAppRequestToHMI,
MOCK_METHOD5(GetBCActivateAppRequestToHMI,
smart_objects::SmartObjectSPtr(
ApplicationConstSharedPtr app,
const protocol_handler::SessionObserver& session_observer,
const policy::PolicyHandlerInterface& policy_handler,
hmi_apis::Common_HMILevel::eType level,
bool send_policy_priority,
ApplicationManager& app_mngr));
MOCK_METHOD2(GetBCCloseApplicationRequestToHMI,
smart_objects::SmartObjectSPtr(ApplicationConstSharedPtr app,
ApplicationManager& app_mngr));
MOCK_METHOD2(GetOnAppInterfaceUnregisteredNotificationToMobile,
ns_smart_device_link::ns_smart_objects::SmartObjectSPtr(
int32_t connection_key,
Expand Down
Loading