Skip to content

Commit ade53aa

Browse files
committed
Fix incorrect setting service status
1 parent 494a8a4 commit ade53aa

File tree

7 files changed

+112
-36
lines changed

7 files changed

+112
-36
lines changed

src/components/application_manager/include/application_manager/application_manager_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,10 @@ class ApplicationManagerImpl
828828
bool result,
829829
std::vector<std::string>& rejected_params) OVERRIDE;
830830

831+
bool SetNaviServiceStatus(uint32_t connection_key,
832+
protocol_handler::ServiceType service_type,
833+
bool is_started) FINAL;
834+
831835
/**
832836
* @brief Callback calls when application starts/stops data streaming
833837
* @param app_id Streaming application id

src/components/application_manager/src/application_manager_impl.cc

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,23 +1790,6 @@ bool ApplicationManagerImpl::StartNaviService(
17901790
LOG4CXX_AUTO_TRACE(logger_);
17911791

17921792
if (HMILevelAllowsStreaming(app_id, service_type)) {
1793-
{
1794-
sync_primitives::AutoLock lock(navi_service_status_lock_);
1795-
1796-
NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id);
1797-
if (navi_service_status_.end() == it) {
1798-
std::pair<NaviServiceStatusMap::iterator, bool> res =
1799-
navi_service_status_.insert(
1800-
std::pair<uint32_t, std::pair<bool, bool> >(
1801-
app_id, std::make_pair(false, false)));
1802-
if (!res.second) {
1803-
LOG4CXX_WARN(logger_, "Navi service refused");
1804-
return false;
1805-
}
1806-
it = res.first;
1807-
}
1808-
}
1809-
18101793
if (service_type == ServiceType::kMobileNav) {
18111794
smart_objects::SmartObject converted_params(smart_objects::SmartType_Map);
18121795
ConvertVideoParamsToSO(converted_params, params);
@@ -1866,17 +1849,11 @@ void ApplicationManagerImpl::OnStreamingConfigured(
18661849
sync_primitives::AutoLock lock(navi_service_status_lock_);
18671850

18681851
NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id);
1869-
if (navi_service_status_.end() == it) {
1852+
if (navi_service_status_.end() == it && !result) {
18701853
LOG4CXX_WARN(logger_, "Application not found in navi status map");
18711854
connection_handler().NotifyServiceStartedResult(app_id, false, empty);
18721855
return;
18731856
}
1874-
1875-
// Fill NaviServices map. Set true to first value of pair if
1876-
// we've started video service or to second value if we've
1877-
// started audio service
1878-
service_type == ServiceType::kMobileNav ? it->second.first = true
1879-
: it->second.second = true;
18801857
}
18811858

18821859
application(app_id)->StartStreaming(service_type);
@@ -1889,33 +1866,70 @@ void ApplicationManagerImpl::OnStreamingConfigured(
18891866
}
18901867
}
18911868

1892-
void ApplicationManagerImpl::StopNaviService(
1893-
uint32_t app_id, protocol_handler::ServiceType service_type) {
1869+
bool ApplicationManagerImpl::SetNaviServiceStatus(
1870+
uint32_t connection_key,
1871+
protocol_handler::ServiceType service_type,
1872+
bool is_started) {
18941873
using namespace protocol_handler;
18951874
LOG4CXX_AUTO_TRACE(logger_);
18961875

1876+
auto app = application(connection_key);
1877+
if (!app) {
1878+
LOG4CXX_DEBUG(
1879+
logger_,
1880+
"Application with app_id: " << connection_key << " is not found");
1881+
return false;
1882+
}
1883+
18971884
{
18981885
sync_primitives::AutoLock lock(navi_service_status_lock_);
18991886

1900-
NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id);
1901-
if (navi_service_status_.end() == it) {
1902-
LOG4CXX_WARN(logger_,
1903-
"No Information about navi service " << service_type);
1887+
NaviServiceStatusMap::iterator it =
1888+
navi_service_status_.find(app->app_id());
1889+
if (navi_service_status_.end() == it && (is_started)) {
1890+
std::pair<NaviServiceStatusMap::iterator, bool> res =
1891+
navi_service_status_.insert(
1892+
std::pair<uint32_t, std::pair<bool, bool> >(
1893+
app->app_id(), std::make_pair(false, false)));
1894+
if (!res.second) {
1895+
LOG4CXX_WARN(logger_, "Navi service refused");
1896+
return false;
1897+
}
1898+
it = res.first;
19041899
} else {
1905-
// Fill NaviServices map. Set false to first value of pair if
1906-
// we've stopped video service or to second value if we've
1907-
// stopped audio service
1908-
service_type == ServiceType::kMobileNav ? it->second.first = false
1909-
: it->second.second = false;
1900+
LOG4CXX_DEBUG(logger_,
1901+
"Application with app_id: "
1902+
<< app->app_id() << " is not found in navi status map");
1903+
return false;
19101904
}
1905+
1906+
service_type == ServiceType::kMobileNav ? it->second.first = is_started
1907+
: it->second.second = is_started;
1908+
LOG4CXX_DEBUG(logger_,
1909+
"ServiceType: " << service_type << " is started: "
1910+
<< std::boolalpha << is_started);
1911+
return true;
19111912
}
1913+
}
1914+
1915+
void ApplicationManagerImpl::StopNaviService(
1916+
uint32_t app_id, protocol_handler::ServiceType service_type) {
1917+
using namespace protocol_handler;
1918+
LOG4CXX_AUTO_TRACE(logger_);
19121919

19131920
ApplicationSharedPtr app = application(app_id);
19141921
if (!app) {
19151922
LOG4CXX_WARN(logger_, "An application is not registered.");
19161923
return;
19171924
}
19181925

1926+
if (!SetNaviServiceStatus(app->app_id(), service_type, false)) {
1927+
LOG4CXX_DEBUG(logger_,
1928+
"Application with app_id: "
1929+
<< app->app_id() << " not found in navi status map");
1930+
return;
1931+
}
1932+
19191933
app->StopStreaming(service_type);
19201934
}
19211935

@@ -2038,7 +2052,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback(
20382052

20392053
if (Compare<ServiceType, EQ, ONE>(
20402054
type, ServiceType::kMobileNav, ServiceType::kAudio)) {
2041-
StopNaviService(session_key, type);
2055+
StopNaviService(static_cast<uint32_t>(session_key), type);
20422056
}
20432057
}
20442058

@@ -2068,6 +2082,18 @@ void ApplicationManagerImpl::ProcessServiceStatusUpdate(
20682082
service_type, service_event, reason, app_id);
20692083

20702084
rpc_service_->ManageHMICommand(notification);
2085+
2086+
if (hmi_apis::Common_ServiceEvent::REQUEST_REJECTED == service_event) {
2087+
if (!app) {
2088+
LOG4CXX_DEBUG(logger_,
2089+
"Application with app_id: " << app_id << " is absent");
2090+
return;
2091+
}
2092+
state_ctrl_.SetRegularState(app,
2093+
mobile_apis::PredefinedWindows::DEFAULT_WINDOW,
2094+
mobile_apis::HMILevel::HMI_NONE,
2095+
true);
2096+
}
20712097
}
20722098

20732099
void ApplicationManagerImpl::OnSecondaryTransportStartedCallback(
@@ -3350,6 +3376,8 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) {
33503376
LOG4CXX_ERROR(logger_, "No info about navi servicies for app");
33513377
return;
33523378
}
3379+
LOG4CXX_DEBUG(logger_, "VEDIO_KEK: " << it->second.first);
3380+
LOG4CXX_DEBUG(logger_, "AUDIO_KEK: " << it->second.second);
33533381
end_video = it->second.first;
33543382
end_audio = it->second.second;
33553383
}

src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class ServiceStatusUpdateHandler {
8080
const protocol_handler::ServiceType service_type,
8181
const ServiceStatus service_status);
8282

83+
void SetNaviServiceStatus(uint32_t app_id,
84+
protocol_handler::ServiceType service_type,
85+
bool is_opened);
86+
8387
private:
8488
ServiceStatusUpdateHandlerListener* listener_;
8589
};

src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class ServiceStatusUpdateHandlerListener {
7070
hmi_apis::Common_ServiceEvent::eType service_event,
7171
utils::Optional<hmi_apis::Common_ServiceStatusUpdateReason::eType>
7272
service_update_reason) = 0;
73+
74+
virtual bool SetNaviServiceStatus(uint32_t connection_key,
75+
protocol_handler::ServiceType service_type,
76+
bool is_started) = 0;
7377
};
7478

7579
} // namespace protocol_handler

src/components/protocol_handler/src/protocol_handler_impl.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ void ProtocolHandlerImpl::SendStartSessionAck(
435435
raw_ford_messages_to_mobile_.PostMessage(
436436
impl::RawFordMessageToMobile(ptr, false));
437437

438+
if ((service_type == ServiceType::kAudio) ||
439+
(service_type == ServiceType::kMobileNav)) {
440+
const uint32_t connection_key =
441+
session_observer_.KeyFromPair(connection_id, session_id);
442+
service_status_update_handler_->SetNaviServiceStatus(
443+
connection_key,
444+
static_cast<protocol_handler::ServiceType>(service_type),
445+
true);
446+
}
447+
438448
LOG4CXX_DEBUG(logger_,
439449
"SendStartSessionAck() for connection "
440450
<< connection_id << " for service_type "
@@ -509,6 +519,13 @@ void ProtocolHandlerImpl::SendStartSessionNAck(
509519
raw_ford_messages_to_mobile_.PostMessage(
510520
impl::RawFordMessageToMobile(ptr, false));
511521

522+
const uint32_t connection_key =
523+
session_observer_.KeyFromPair(connection_id, session_id);
524+
service_status_update_handler_->SetNaviServiceStatus(
525+
connection_key,
526+
static_cast<protocol_handler::ServiceType>(service_type),
527+
false);
528+
512529
LOG4CXX_DEBUG(logger_,
513530
"SendStartSessionNAck() for connection "
514531
<< connection_id << " for service_type "
@@ -572,6 +589,14 @@ void ProtocolHandlerImpl::SendEndSessionNAck(
572589
raw_ford_messages_to_mobile_.PostMessage(
573590
impl::RawFordMessageToMobile(ptr, false));
574591

592+
const uint32_t connection_key = session_observer_.KeyFromPair(
593+
connection_id, static_cast<uint8_t>(session_id));
594+
595+
service_status_update_handler_->SetNaviServiceStatus(
596+
connection_key,
597+
static_cast<protocol_handler::ServiceType>(service_type),
598+
false);
599+
575600
LOG4CXX_DEBUG(logger_,
576601
"SendEndSessionNAck() for connection "
577602
<< connection_id << " for service_type "

src/components/protocol_handler/src/service_status_update_handler.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@ void ServiceStatusUpdateHandler::OnServiceUpdate(
114114
}
115115
}
116116
}
117+
118+
void ServiceStatusUpdateHandler::SetNaviServiceStatus(uint32_t app_id,
119+
ServiceType service_type,
120+
bool is_opened) {
121+
listener_->SetNaviServiceStatus(app_id, service_type, is_opened);
122+
}
117123
} // namespace protocol_handler

src/components/protocol_handler/test/include/protocol_handler/mock_service_status_update_handler_listener.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class MockServiceStatusUpdateHandlerListener
4949
hmi_apis::Common_ServiceType::eType,
5050
hmi_apis::Common_ServiceEvent::eType,
5151
utils::Optional<hmi_apis::Common_ServiceStatusUpdateReason::eType>));
52+
53+
MOCK_METHOD3(SetNaviServiceStatus,
54+
bool(uint32_t connection_key,
55+
protocol_handler::ServiceType service_type,
56+
bool is_started));
5257
};
5358
} // namespace protocol_handler_test
5459
} // namespace components

0 commit comments

Comments
 (0)