common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / logger_service / server / src / ss_logger_error_event.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SS_LoggerService
19 /// \brief    This file supports error event logging.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include "ss_logger_error_event.h"
23 #include <string.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <boost/bind.hpp>
27 #include <unistd.h>
28 #include <sys/wait.h>
29 #include <native_service/frameworkunified_framework_if.h>
30 #include <system_service/ss_sm_client_if.h>
31 #include <system_service/ss_client_names.h>
32 #include <system_service/ss_logger_service_protocol.h>
33 #include <system_service/ss_logger_service.h>
34 #include <system_service/ss_services.h>
35 #include <system_service/ss_templates.h>
36 #include <stub/el_mem.h>
37 #include <native_service/cl_process.h>
38 #include <stub/Clock_API.h>
39 #include <string>
40 #include "loggerservicedebug_loggerservicelog.h"
41 #include "loggerservicedebug_thread_if.h"
42 #include "ss_logger_service_callbacks.h"
43 #include "ss_logger_error_event_archive.h"
44 #include "ss_logger_common.h"
45 #include "ss_logger_types.h"
46 #include "ss_logger_fs_directory.h"
47
48 CErrorEvent::CErrorEvent()
49     : m_hApp(NULL),
50       m_bIsPrevEventCompleted(true),
51       m_errorEventNtfData(),
52       m_pLoggerCfg(NULL),
53       m_pReaderWriterControl(NULL),
54       m_ServiceName(""),
55       m_time(0),
56       m_currentEventTriggerNumber(0),
57       m_diagsessionhandle(NULL),
58       m_thrdEvntLogWriter(NULL),
59       m_sfd(-1) {  // LCOV_EXCL_BR_LINE 11:Unexpected branch
60   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
61   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
62 }  // LCOV_EXCL_BR_LINE 11:Unexpected branch
63
64 CErrorEvent::~CErrorEvent() {  // LCOV_EXCL_START 14:globle instance
65   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
66   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
67   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
68 }
69 // LCOV_EXCL_STOP
70
71 EFrameworkunifiedStatus CErrorEvent::Initialize(HANDLE f_hApp, CLoggerCfg *f_pLoggerCfg,
72                                    CReaderWriterControl *f_pReaderWriterControl,
73                                    HANDLE f_thrdEvntLogWriter,
74                                    std::string f_strEvntLogQueWorkerName) {
75   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
76   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
77   Timer *l_pTimer;
78
79   m_sfd = CL_ProcessInit();
80   if (m_sfd == -1) {  // LCOV_EXCL_BR_LINE 8:Because the process initialization is guaranteed to be successful
81     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
82     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. m_sfd CL_ProcessInit() failed \n.");  // LCOV_EXCL_LINE 8:Because the process initialization is guaranteed to be successful
83   }
84
85   SS_LoggerServerEvents l_errorEventStateEvents[] = {
86       SS_LOGGER_SCREENCAPTURE_EVT };
87
88   FrameworkunifiedProtocolCallbackHandler l_smCallbacks[] = {
89   // Logging Protocol Callbacks
90       { SS_SM_EVENT_ERROR_TO_SSL, boost::bind(&CErrorEvent::OnStartLogging,
91                                               this, _1) }, {
92           SS_SM_ERROR_EVENT_LOGGING_START_RSPN, boost::bind(
93               &CErrorEvent::OnLogStartResponse, this, _1) }, {
94           SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind(
95               &CErrorEvent::OnArtifactResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch
96
97   FrameworkunifiedProtocolCallbackHandler l_selfCallbacks[] = {
98   // Logging Protocol Callbacks
99       { SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ, boost::bind(
100           &CErrorEvent::OnArtifactRequest, this, _1) }, {
101           SS_SM_ERROR_EVENT_ARTIFACT_RSPN, boost::bind(
102               &CErrorEvent::OnArtifactResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch
103
104   FrameworkunifiedProtocolCallbackHandler l_requesterCallbacks[] = { {
105       SS_LOGGER_SCREENCAPTURE_EVT_ACK, boost::bind(
106           &CErrorEvent::OnObtainScreenShotResponse, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch
107
108   FrameworkunifiedProtocolCallbackHandler l_storageThreadCallbacks[] = { {
109       eLoggerStorageThreadCmdOK, boost::bind(&CErrorEvent::OnStorageResponseOk,
110                                              this, _1) }, {
111       eLoggerStorageThreadCmdWriteFailed, boost::bind(
112           &CErrorEvent::OnStorageResponseWriteFailed, this, _1) }, {
113       eLoggerStorageThreadCmdNotFound, boost::bind(
114           &CErrorEvent::OnStorageResponseNotFound, this, _1) }, {
115       eLoggerStorageThreadCmdNoWritten, boost::bind(
116           &CErrorEvent::OnStorageResponseNoWritten, this, _1) } };  // LCOV_EXCL_BR_LINE 11:Unexpected branch
117   for (UI_32 i = 0; i < _countof(l_requesterCallbacks); i++) {
118     m_requesterCallbacksVec.push_back(l_requesterCallbacks[i]);  // LCOV_EXCL_BR_LINE 11:Unexpected branch
119   }
120
121   if (NULL == f_hApp) {  // LCOV_EXCL_BR_LINE 6:As it is not always NULL
122     // LCOV_EXCL_START 6:As it is not always NULL
123     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
124     l_eStatus = eFrameworkunifiedStatusInvldHandle;
125     FRAMEWORKUNIFIEDLOG(
126         ZONE_ERR, __FUNCTION__,
127         " Error. Argument f_hApp passed NULL pointer. Initialization failed.");
128     // LCOV_EXCL_STOP
129   } else if (NULL == (m_thrdEvntLogWriter = f_thrdEvntLogWriter)) {  // LCOV_EXCL_BR_LINE 6:As it is not always NULL
130     // LCOV_EXCL_START 6:As it is not always NULL
131     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
132     l_eStatus = eFrameworkunifiedStatusInvldHandle;
133     FRAMEWORKUNIFIEDLOG(
134         ZONE_ERR, __FUNCTION__,
135         " Error. Argument f_hApp passed NULL pointer. Initialization failed.");
136     // LCOV_EXCL_STOP
137   } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_errorEventCfg.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success
138     // LCOV_EXCL_START 200:To ensure success
139     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
140     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
141            " Error. m_errorEventCfg.Initialize() returned: %d.", l_eStatus);
142     // LCOV_EXCL_STOP
143   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_LOGGER, l_selfCallbacks, _countof(l_selfCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
144     // LCOV_EXCL_START 4:NSFW
145     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
146     FRAMEWORKUNIFIEDLOG(
147         ZONE_ERR,
148         __FUNCTION__,
149         " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.",
150         l_eStatus);
151     // LCOV_EXCL_STOP
152   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, SERVICE_SYSMANAGER, l_smCallbacks, _countof(l_smCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
153     // LCOV_EXCL_START 4:NSFW
154     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
155     FRAMEWORKUNIFIEDLOG(
156         ZONE_ERR,
157         __FUNCTION__,
158         " Error. FrameworkunifiedAttachCallbacksToDispatcher(SERVICE_SYSMANAGER) returned: %d.",
159         l_eStatus);
160     // LCOV_EXCL_STOP
161   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDefineStateEvents(f_hApp, &l_errorEventStateEvents, static_cast<UI_32>(_countof(l_errorEventStateEvents))))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
162     // LCOV_EXCL_START 4:NSFW
163     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
164     FRAMEWORKUNIFIEDLOG(
165         ZONE_ERR,
166         __FUNCTION__,
167         " Error. FrameworkunifiedDefineStateEvents(SS_LOGGER_SCREENCAPTURE_EVT) returned: %d",
168         l_eStatus);
169     // LCOV_EXCL_STOP
170   } else if (NULL == f_pLoggerCfg) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
171     // LCOV_EXCL_START 200:As it is not always NULL
172     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
173     l_eStatus = eFrameworkunifiedStatusNullPointer;
174     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. f_pLoggerCfg passed NULL pointer.");
175     // LCOV_EXCL_STOP
176   } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerPopups.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
177     // LCOV_EXCL_START 200:To ensure success
178     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
179     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
180            " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.",
181            l_eStatus);
182     // LCOV_EXCL_STOP
183   } else if (NULL == f_pReaderWriterControl) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
184     // LCOV_EXCL_START 200:As it is not always NULL
185     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
186     l_eStatus = eFrameworkunifiedStatusNullPointer;
187     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
188            " Error. Argument f_pReaderWriterControl passed NULL pointer.");
189     // LCOV_EXCL_STOP
190   } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerStorage.Initialize(f_hApp, AppName, f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
191     // LCOV_EXCL_START 200:To ensure success
192     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
193     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
194            " Error. m_loggerPopups.Initialize(f_pLoggerCfg) returned: %d.",
195            l_eStatus);
196     // LCOV_EXCL_STOP
197   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher( f_hApp, ERROR_EVENT_STORAGE_QUEUE_NAME, l_storageThreadCallbacks, _countof(l_storageThreadCallbacks)))) {  // LCOV_EXCL_BR_LINE 4:NSFW  // NOLINT[whitespace/line_length]
198     // LCOV_EXCL_START 4:NSFW
199     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
200     FRAMEWORKUNIFIEDLOG(
201         ZONE_ERR,
202         __FUNCTION__,
203         " Error. FrameworkunifiedAttachCallbacksToDispatcher(ERROR_EVENT_STORAGE_QUEUE_NAME) returned: %d.",
204         l_eStatus);
205     // LCOV_EXCL_STOP
206   } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_loggerCanEvent.Initialize(f_pLoggerCfg))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
207     // LCOV_EXCL_START 200:To ensure success
208     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
209     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
210            " Error. m_loggerCanEvent.Initialize() returned: %d.", l_eStatus);
211     // LCOV_EXCL_STOP
212   } else {
213     m_hApp = f_hApp;
214     m_pLoggerCfg = f_pLoggerCfg;
215     m_pReaderWriterControl = f_pReaderWriterControl;
216     l_eStatus = m_loggerUtil.Initialize(m_pLoggerCfg);  // LCOV_EXCL_BR_LINE 11:Unexpected branch
217     LOG_STATUS_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 5:macro
218                           "CLoggerUtil::m_loggerUtil.Initialize(m_pLoggerCfg)");
219
220     l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN];
221     l_pTimer->Initialize(
222         f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_LOGGING_START_RSPN,
223         boost::bind(&CErrorEvent::OnLogStartResponseTimeout, this, _1));  // LCOV_EXCL_BR_LINE 11:Unexpected branch
224
225     l_pTimer = &m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN];
226     l_pTimer->Initialize(
227         f_hApp, SS_LOGGER_ERROR_EVENT_TIMER_ID_ARTIFACT_RESPONSE,
228         boost::bind(&CErrorEvent::OnArtifactResponseTimeout, this, _1));  // LCOV_EXCL_BR_LINE 11:Unexpected branch
229     m_ServiceName = "";
230   }
231
232   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
233   return (l_eStatus);
234 }
235
236 ///////////////////////////////////////////////////////////////////////////
237 //  Function : RegisterSessionErrorEvent
238 //  brief    : Register session event. This function is called within the
239 //             context of the System Manager session acknowledgment handler.
240 ///////////////////////////////////////////////////////////////////////////
241 EFrameworkunifiedStatus CErrorEvent::RegisterSessionErrorEvent(HANDLE f_hSession) {
242   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
243   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
244
245   l_eStatus = FrameworkunifiedRegisterEvent(f_hSession, SS_SM_EVENT_ERROR_TO_SSL);
246   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedRegisterEvent(SS_SM_EVENT_ERROR_TO_SSL)");  // LCOV_EXCL_BR_LINE 5:macro
247
248   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
249   return (l_eStatus);
250 }
251
252 ///////////////////////////////////////////////////////////////////////////
253 //  Function : OnOpenSession
254 //  brief    : Called when a requester opens a session with SS_Logger
255 //             service.  This function attaches error event callbacks
256 //             to the dispatcher with the source set to the requester.
257 ///////////////////////////////////////////////////////////////////////////
258 EFrameworkunifiedStatus CErrorEvent::OnOpenSession(HANDLE f_hApp, PCSTR f_pRequesterName,
259                                       HANDLE f_hSession) {
260   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
261   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
262
263   l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(f_hApp, f_pRequesterName,
264                                              &m_requesterCallbacksVec[0],
265                                              static_cast<UI_32>(m_requesterCallbacksVec.size()),
266                                              f_hSession);
267
268   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher(f_hSession)");  // LCOV_EXCL_BR_LINE 5:macro
269
270   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
271   return (l_eStatus);
272 }
273
274 ///////////////////////////////////////////////////////////////////////////
275 //  Function : OnOpenSession
276 //  brief    : Called when a requester opens a session with SS_Logger
277 //             service.  This function attaches error event callbacks
278 //             to the dispatcher with the source set to the requester.
279 ///////////////////////////////////////////////////////////////////////////
280 EFrameworkunifiedStatus CErrorEvent::OnCloseSession(HANDLE f_hApp, PCSTR f_pRequesterName,
281                                        HANDLE f_hSession) {
282   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
283   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
284   UI_32 l_cmdIdArr[m_requesterCallbacksVec.size()]; // NOLINT (runtime/arrays)
285
286   for (UI_32 i = 0; i < m_requesterCallbacksVec.size(); i++) {
287     l_cmdIdArr[i] = m_requesterCallbacksVec[i].iCmd;
288   }
289
290   l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(f_hApp, f_pRequesterName,
291                                                l_cmdIdArr,
292                                                static_cast<UI_32>(m_requesterCallbacksVec.size()),
293                                                f_hSession);
294
295   LOG_STATUS_IF_ERRORED(l_eStatus, "FrameworkunifiedAttachCallbacksToDispatcher()");  // LCOV_EXCL_BR_LINE 5:macro
296
297   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
298   return (l_eStatus);
299 }
300
301 ///////////////////////////////////////////////////////////////////////////
302 //  Function : OnStartLogging
303 //  brief    : Called by SS_Logger and external services to begin logging
304 //             artifact collection. This function sends a logging request
305 //             to System Manager. See SS_SM_EVENT_ERROR_TO_SSL.
306 ///////////////////////////////////////////////////////////////////////////
307 EFrameworkunifiedStatus CErrorEvent::OnStartLogging(HANDLE f_hApp) {
308   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
309   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
310   SMErrorEventNtfData l_eventErrorNtfData;
311
312   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 5:macro
313
314   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<SMErrorEventNtfData>(f_hApp, l_eventErrorNtfData))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
315     // when failed to ReadMsg, we can't know event-type for action, so nothing is able to do.
316     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
317     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 200:To ensure success
318   } else {
319     if (TRUE == this->m_pLoggerCfg->IsLoggingEnabled()) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
320       if (TRUE == m_bIsPrevEventCompleted) {
321         TLoggerErrorEvent l_eventData = l_eventErrorNtfData;
322
323         if (IsNeedVerify(l_eventData.EventType)) {
324           // if need output log to external storage, check whether device is authenticated or not.
325           VerifyExtStorage(l_eventData);
326         }
327
328         uint8_t status;
329         Clock_getSystemTimeY2K38(&m_time, &status);
330         m_currentEventTriggerNumber = m_pLoggerCfg->GetUserInvokedCounter();
331         l_eStatus = m_loggerUtil.checkDestinationAvailable(l_eventData);
332         if (eFrameworkunifiedStatusOK == l_eStatus) {
333           m_bIsPrevEventCompleted = false; /* See timer start / timeout handler below.             */
334
335           m_artifactResponseVec.clear();
336
337           m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */
338           m_errorEventNtfData.EventBitMask = m_errorEventCfg
339               .GetEventsForErrorEvent(l_eventErrorNtfData.EventType);
340           l_eStatus = SendLogStartRequestToSystemManager(
341               m_errorEventNtfData.EventType);
342           LOG_STATUS_IF_ERRORED(l_eStatus,
343                                 "SendLogStartRequestToSystemManager()");
344           l_eStatus = m_loggerCanEvent.PublishStartEvent(f_hApp,
345                                                          m_errorEventNtfData);
346           LOG_STATUS_IF_ERRORED(
347               l_eStatus,
348               "m_loggerCanEvent.PublishStartEvent(f_hApp,m_errorEventNtfData);");
349
350           bool result =
351               m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN]
352                   .Start(m_loggingStartRspnToSec, 0, 0, 0);
353           if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
354             // LCOV_EXCL_START 200:As it is always TRUE
355             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
356             FRAMEWORKUNIFIEDLOG(
357                 ZONE_ERR,
358                 __FUNCTION__,
359                 " Error. Failed to start timer kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN.");
360             // LCOV_EXCL_STOP
361           }
362         } else {
363           FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
364                  " Warning. Destination not available. ");
365           m_errorEventNtfData = l_eventErrorNtfData; /* Overwrite m_eventErrorNtfData when logging complete. */
366           m_errorEventNtfData.EventBitMask = m_errorEventCfg
367               .GetEventsForErrorEvent(l_eventErrorNtfData.EventType);
368           l_eStatus = OnStorageResponseNotFound(f_hApp);
369           LOG_STATUS_IF_ERRORED(l_eStatus, "OnStorageResponseNotFound(f_hApp)");
370         }
371       } else {
372         // Not-Need Resp to SM, because of keep logging sequance.
373         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
374                " Error. Logging already in progress. Event dropped.");
375       }
376     } else {
377       // LCOV_EXCL_START 200:As it is always TRUE
378       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
379       if (l_eventErrorNtfData.isNeedReboot == TRUE) {
380         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
381                "System will reboot soon, so stop logging function.");
382         StopLoggingFunction(f_hApp);
383       }
384       FRAMEWORKUNIFIEDLOG(
385           ZONE_INFO,
386           __FUNCTION__,
387           "Logging is disabled! Dropping Event. Sending Complete to SS_SystemManager");
388       l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);
389       LOG_STATUS_IF_ERRORED(l_eStatus,
390                             "SendLogCompleteRequestToSystemManager()");
391       // LCOV_EXCL_STOP
392     }
393   }
394
395   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
396   return (l_eStatus);
397 }
398
399 ///////////////////////////////////////////////////////////////////////////
400 //  Function : OnLogStartResponse
401 //  brief    : Called by System Manager after the acknowledgment of the
402 //             logging session start request.  This function starts the
403 //             artifact collection process. See
404 //             SS_SM_ERROR_EVENT_LOGGING_START_RSPN.
405 ///////////////////////////////////////////////////////////////////////////
406 EFrameworkunifiedStatus CErrorEvent::OnLogStartResponse(HANDLE f_hApp) {
407   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
408   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
409   m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_LOGGING_START_RSPN].Stop();
410   m_errorEventCfg.GetArtifactRequestVec(m_errorEventNtfData.EventType,
411                                         m_artifactRequestVec);
412
413   l_eStatus = RequestNextArtifact(f_hApp);
414   LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()");
415
416   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
417   return (l_eStatus);
418 }
419
420 ///////////////////////////////////////////////////////////////////////////
421 //  Function : OnLogStartResponseTimeout
422 //  brief    : Called when / if SM fails to respond to a logging start
423 //             request and the logging star response timer expires.
424 ///////////////////////////////////////////////////////////////////////////
425 EFrameworkunifiedStatus CErrorEvent::OnLogStartResponseTimeout(HANDLE f_hApp) {
426   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
427   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
428
429   FRAMEWORKUNIFIEDLOG(
430       ZONE_ERR,
431       __FUNCTION__,
432       " Error. SM failed to respond to a logging start request in the required amount of time.");
433
434   m_bIsPrevEventCompleted = TRUE;
435
436   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
437   return (l_eStatus);
438 }
439
440 ///////////////////////////////////////////////////////////////////////////
441 //  Function : RequestNextArtifact
442 //  brief    : This function requests the next artifact from the service
443 //             that owns the artifact.  If no artifacts remain, this
444 //             function performs initiates artifact post processing.
445 ///////////////////////////////////////////////////////////////////////////
446 EFrameworkunifiedStatus CErrorEvent::RequestNextArtifact(HANDLE f_hApp) {
447   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
448   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
449   UI_32 l_timeoutSec;
450   UI_32 l_timeoutMs;
451
452   if (0 != m_artifactRequestVec.size()) {
453     TLoggingArtifact &l_nextArtifact = m_artifactRequestVec.back();
454     l_eStatus = m_loggerPopups.ShowStartPopup(
455         f_hApp, m_errorEventNtfData, &m_artifactRequestVec,
456         m_loggerUtil.getDestination(m_errorEventNtfData));
457
458     LOG_STATUS_IF_ERRORED(
459         l_eStatus,
460         "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )");
461
462     TEXT(__FUNCTION__,
463          "Requesting next artifact ID:%d from:%s, with timeout:%d ms.",
464          l_nextArtifact.ArtifactId,
465          l_nextArtifact.Information.OwnerServiceName.c_str(),
466          l_nextArtifact.Information.RequestTimeoutMs);
467
468     l_timeoutSec = l_nextArtifact.Information.RequestTimeoutMs / 1000;
469     l_timeoutMs = l_nextArtifact.Information.RequestTimeoutMs % 1000;
470     bool result =
471         m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Start(
472             l_timeoutSec, l_timeoutMs, 0, 0);
473     if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
474       // LCOV_EXCL_START 200:As it is always TRUE
475       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
476       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
477              "Failed to start timer kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN.");
478       // LCOV_EXCL_STOP
479     }
480     switch (l_nextArtifact.Information.Cb.Type) {
481       case eCbTypePath: {
482         l_eStatus = CheckPathForArtifact(f_hApp, l_nextArtifact);
483       }
484         break;
485
486       case eCbTypeFunction: {
487         if (l_nextArtifact.Information.Cb.Function == NULL) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
488           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
489           l_eStatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 200:As it is not always NULL
490         } else {
491           l_eStatus = l_nextArtifact.Information.Cb.Function(f_hApp,
492                                                              l_nextArtifact);
493           LOG_STATUS_IF_ERRORED(
494               l_eStatus,
495               "l_nextArtifact.Information.Cb.Function(f_hApp, l_nextArtifact)");
496         }
497       }
498         break;
499
500       case eCbTypeInvalid:
501       default:
502       {
503         FRAMEWORKUNIFIEDLOG(
504             ZONE_ERR,
505             __FUNCTION__,
506             " Error. Unknown artifact or artifact owner for artifact ID:"
507             " %d. Invalid logging artifact configuration likely.",
508             l_nextArtifact.ArtifactId);
509       }
510         break;
511     }
512   } else {
513     if ((m_errorEventNtfData.EventType == eErrorEventTypeUserInvokedClearLogs)
514         || (m_errorEventNtfData.EventType
515             == eErrorEventTypeUserInvokedCollectNaviLog)) {
516       l_eStatus = this->OnStorageResponseOk(f_hApp);
517       return (l_eStatus);
518     }
519     uint8_t status;
520     Clock_getSystemTimeY2K38(&m_time, &status);
521     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
522            " Info. All logging error event artifacts have been collected.");
523     l_eStatus = m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData);
524     LOG_STATUS_IF_ERRORED(
525         l_eStatus,
526         "m_loggerUtil.checkDestinationAvailable(m_errorEventNtfData)");
527     if (eFrameworkunifiedStatusOK == l_eStatus) {
528       /* Check one last time after all logs have been collected   */
529       /* if we should show popup for archiving and writing to USB */
530       l_eStatus = m_loggerPopups.ShowStartPopup(
531           f_hApp, m_errorEventNtfData, &m_artifactRequestVec,
532           m_loggerUtil.getDestination(m_errorEventNtfData));
533       LOG_STATUS_IF_ERRORED(
534           l_eStatus,
535           "m_loggerPopups.ShowStartPopup(f_hApp,m_errorEventNtfData,&m_artifactRequestVec )");
536
537       l_eStatus = m_loggerUtil.getFilePathAndName(f_hApp, m_errorEventNtfData,
538                                                   m_time, m_archiveDestination);
539       LOG_STATUS_IF_ERRORED(
540           l_eStatus,
541           "m_loggerUtil.getFilePathAndName()");
542
543       std::string destination_path = m_loggerUtil.getDestination(
544           m_errorEventNtfData);
545       if (destination_path.compare(m_pLoggerCfg->m_emmcOutputPath) == 0) {
546         if (eFrameworkunifiedStatusOK
547             != m_loggerUtil.deleteOldEmmcLog(m_archiveDestination,
548                                              m_errorEventNtfData.EventType)) {
549           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
550                  " Error. m_loggerUtil.deleteOldEmmcLog()");
551         }
552       }
553
554       l_eStatus = this->m_loggerStorage.Start(m_archiveDestination,
555                                               this->m_artifactResponseVec,
556                                               m_time);
557       LOG_STATUS_IF_ERRORED(
558           l_eStatus,
559           "m_loggerStorage.Start()");
560       if (l_eStatus != eFrameworkunifiedStatusOK) {
561         l_eStatus = this->OnStorageResponseWriteFailed(f_hApp);
562         LOG_STATUS_IF_ERRORED(l_eStatus,
563                               "this->OnStorageResponseWriteFailed(f_hApp)");
564       }
565     } else {
566       l_eStatus = this->OnStorageResponseNotFound(f_hApp);
567       LOG_STATUS_IF_ERRORED(
568           l_eStatus,
569           "this->OnStorageResponseNotFound(f_hApp)");
570     }
571   }
572
573   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
574   return (l_eStatus);
575 }
576
577 ///////////////////////////////////////////////////////////////////////////
578 //  Function : OnArtifactResponse
579 //  brief    : This function is called when an artifact has been made ready
580 //             by the owning service.
581 ///////////////////////////////////////////////////////////////////////////
582 EFrameworkunifiedStatus CErrorEvent::OnArtifactResponse(HANDLE f_hApp) {
583   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
584   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
585   ARTIFACT_RESPONSE l_artifactResponse;
586
587   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<ARTIFACT_RESPONSE>(f_hApp, l_artifactResponse))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
588     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
589     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 200:To ensure success
590   } else {
591     m_errorEventTimers[kSSL_ERROR_EVENT_TIMER_ARTIFACT_RSPN].Stop();
592
593     // Prevent processing of artifacts that arrive after the error event logging session has completed.
594     if (m_artifactRequestVec.size() > 0) {
595       TEXT(__FUNCTION__, "Artifact ID:%d received.",
596            l_artifactResponse.ArtifactId);
597
598       TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back();
599       if (l_artifactCurr.ArtifactId != l_artifactResponse.ArtifactId) {
600         TEXT(
601             __FUNCTION__,
602             "Failure collecting current artifact. Expected artifact ID:%d, received artifact ID:%d."
603             " Ignoring received artifact.",
604             l_artifactCurr.ArtifactId, l_artifactResponse.ArtifactId);
605       } else {
606         TLoggingArtifactResponse l_response;
607         l_response.ArtifactId = l_artifactResponse.ArtifactId;
608         l_response.Filepath = l_artifactResponse.FilePathAndName;
609         l_response.Remove = l_artifactCurr.Information.Remove;
610         m_artifactResponseVec.push_back(l_response);
611         m_artifactRequestVec.pop_back();  // Remove received artifact from request vector.
612         l_eStatus = RequestNextArtifact(f_hApp);
613         LOG_STATUS_IF_ERRORED(l_eStatus, "RequestNextArtifact()");
614       }
615     } else {
616       FRAMEWORKUNIFIEDLOG(
617           ZONE_ERR,
618           __FUNCTION__,
619           " Error. Received spurious artifact ID: %d. No error event logging session active.",
620           l_artifactResponse.ArtifactId);  // LCOV_EXCL_BR_LINE 5:macro
621     }
622   }
623
624   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
625   return (l_eStatus);
626 }
627
628 ///////////////////////////////////////////////////////////////////////////
629 //  Function : OnArtifactResponseTimeout
630 //  brief    : This function is called when a requested artifact response
631 //             fails to arrive in the required amount of time.
632 ///////////////////////////////////////////////////////////////////////////
633 EFrameworkunifiedStatus CErrorEvent::OnArtifactResponseTimeout(HANDLE f_hApp) {
634   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
635   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
636
637   if (m_artifactRequestVec.size() > 0) {  // LCOV_EXCL_BR_LINE 200:As it cannot always be 0
638     TLoggingArtifact &l_artifactCurr = m_artifactRequestVec.back();
639
640     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
641            " Error. Artifact response timer expired for artifact ID: %d.",
642            l_artifactCurr.ArtifactId);
643
644     // Remove artifact from request vector.
645     m_artifactRequestVec.pop_back();
646
647     RequestNextArtifact(f_hApp);
648   }
649
650   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
651   return (l_eStatus);
652 }
653
654 ///////////////////////////////////////////////////////////////////////////
655 //  Function : OnArtifactRequest
656 //  brief    : This function services an artifact request generated by
657 //             the error event sub system.  The requested artifact will
658 //             be one of the artifacts owned by SSL.
659 ///////////////////////////////////////////////////////////////////////////
660 EFrameworkunifiedStatus CErrorEvent::OnArtifactRequest(HANDLE f_hApp) {
661   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
662   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
663   EArtifactId l_requestedArtifactId;
664
665   if (eFrameworkunifiedStatusOK
666       != (l_eStatus = ReadMsg<EArtifactId>(f_hApp, l_requestedArtifactId))) {
667     LOG_ERROR("ReadMsg()");
668   } else {
669     switch (l_requestedArtifactId) {
670       case eArtifactIdInterfaceunifiedDebugLog:
671         l_eStatus = OnObtainLoggerserviceLogRequest(f_hApp);
672         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainLoggerserviceLogRequest()");
673         break;
674
675       case eArtifactIdTransmitLog:
676         l_eStatus = OnObtainTransmitLogRequest(f_hApp);
677         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainTransmitLogRequest()");
678         break;
679
680       case eArtifactIdPerformanceLog:
681         l_eStatus = OnObtainPerformanceLogRequest(f_hApp);
682         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainPerformanceLogRequest()");
683         break;
684
685       case eArtifactIdScreenShot:
686         l_eStatus = OnObtainScreenShotRequest(f_hApp);
687         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainScreenShotRequest()");
688         break;
689
690       case eArtifactIdKernelLog:
691         l_eStatus = OnObtainKernelLogInfoRequest(f_hApp);
692         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainKernelLogInfoRequest()");
693         break;
694
695       case eArtifactIdDRInitialLog:
696         l_eStatus = OnObtainDRInitialLogRequest(f_hApp);
697         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRInitialLogRequest()");
698         break;
699
700       case eArtifactIdDRLocationLog:
701         l_eStatus = OnObtainDRLocationLogRequest(f_hApp);
702         LOG_STATUS_IF_ERRORED(l_eStatus, "OnObtainDRLocationLogRequest()");
703         break;
704
705       case eArtifactIdClearAllLog:
706         l_eStatus = OnClearAllLogRequest(f_hApp);
707         LOG_STATUS_IF_ERRORED(l_eStatus, "OnClearAllLogRequest()");
708         break;
709
710       case eArtifactIdNaviLog:
711         l_eStatus = OnNaviLogRequest(f_hApp);
712         LOG_STATUS_IF_ERRORED(l_eStatus, "OnNaviLogRequest()");
713         break;
714
715       default:
716         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
717                " Error. Unsupported logging artifact requested: %d.",
718                l_requestedArtifactId);
719         break;
720     }
721   }
722
723   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
724   return (l_eStatus);
725 }
726
727 ///////////////////////////////////////////////////////////////////////////
728 //  Function : OnStorageResponseOk
729 //  brief    : This function services response from the storage thread. It
730 //             is called when the logs have been stored successfully.
731 ///////////////////////////////////////////////////////////////////////////
732 EFrameworkunifiedStatus CErrorEvent::OnStorageResponseOk(HANDLE f_hApp) {
733   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
734   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
735
736   l_eStatus = this->m_loggerPopups.ShowEndPopup(f_hApp, m_errorEventNtfData,
737                                                 m_archiveDestination);
738   LOG_STATUS_IF_ERRORED(
739       l_eStatus,
740       "this->m_loggerPopups.ShowEndPopup(f_hApp,m_errorEventNtfData,m_archiveDestination)");
741
742   if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
743     l_eStatus = sendDiagEventResponse();
744     LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventResponse()");
745   }
746   if (m_errorEventNtfData.isNeedReboot == TRUE) {
747     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
748            "System will reboot soon, so stop logging function.");
749     StopLoggingFunction(f_hApp);
750   }
751   m_bIsPrevEventCompleted = true;
752   l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK);
753
754   l_eStatus = m_loggerCanEvent.PublishEndEvent(f_hApp, m_errorEventNtfData,
755                                                m_currentEventTriggerNumber,
756                                                m_time);
757   LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishEndEvent();");
758   LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()");
759   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
760   return (l_eStatus);
761 }
762
763 ///////////////////////////////////////////////////////////////////////////
764 //  Function : OnStorageResponseWriteFailed
765 //  brief    : This function services response from the storage thread. It
766 //             is called when the logs failed to be written to the target
767 //             destination.
768 ///////////////////////////////////////////////////////////////////////////
769 EFrameworkunifiedStatus CErrorEvent::OnStorageResponseWriteFailed(HANDLE f_hApp) {
770   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
771   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
772   l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
773                                             (UI_16) eWriteToDeviceFailed);
774   LOG_STATUS_IF_ERRORED(
775       l_eStatus, "m_loggerPopups.ShowErrorPopup(f_hApp, eWriteToDeviceFailed)");
776
777   if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
778     sendDiagEventErrorResponse(eDEVICE_WRITE_ERROR);
779   }
780   if (m_errorEventNtfData.isNeedReboot == TRUE) {
781     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
782            "System will reboot soon, so stop logging function.");
783     StopLoggingFunction(f_hApp);
784   }
785   m_bIsPrevEventCompleted = true;
786   l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);
787
788   l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
789   TRUE,
790                                                  m_currentEventTriggerNumber,
791                                                  m_time);
792   LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");
793
794   LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()");
795   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
796   return (l_eStatus);
797 }
798
799 ///////////////////////////////////////////////////////////////////////////
800 //  Function : OnStorageResponseNotFound
801 //  brief    : This function services response from the storage thread. It
802 //             is called when the logs failed to be written to the target
803 //             destination because the target was not found
804 ///////////////////////////////////////////////////////////////////////////
805 EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNotFound(HANDLE f_hApp) {
806   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
807   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
808   l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
809                                             (UI_16) eSelectedDeviceNotFound);
810   LOG_STATUS_IF_ERRORED(
811       l_eStatus,
812       "m_loggerPopups.ShowErrorPopup(f_hApp, eSelectedDeviceNotFound)");
813
814   if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
815     l_eStatus = sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE);
816     LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eDEVICE_NOT_AVAILABLE)");
817   }
818   if (m_errorEventNtfData.isNeedReboot == TRUE) {
819     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
820            "System will reboot soon, so stop logging function.");
821     StopLoggingFunction(f_hApp);
822   }
823   m_bIsPrevEventCompleted = true;
824   l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusFail);
825
826   l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
827   TRUE,
828                                                  m_currentEventTriggerNumber,
829                                                  m_time);
830   LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");
831
832   LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()");
833   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
834   return (l_eStatus);
835 }
836
837 ///////////////////////////////////////////////////////////////////////////
838 //  Function : OnStorageResponseNoWritten
839 //  brief    : This function services response from the storage thread. It
840 //             is called when no logs where found.
841 ///////////////////////////////////////////////////////////////////////////
842 EFrameworkunifiedStatus CErrorEvent::OnStorageResponseNoWritten(HANDLE f_hApp) {
843   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
844   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
845
846   l_eStatus = m_loggerPopups.ShowErrorPopup(f_hApp, m_errorEventNtfData,
847                                             (UI_16) eNoLogToStore);
848   LOG_STATUS_IF_ERRORED(l_eStatus,
849                         "m_loggerPopups.ShowErrorPopup(f_hApp, eNoLogToStore)");
850
851   if (m_errorEventNtfData.EventType == eErrorEventTypeDiagEvent) {
852     l_eStatus = sendDiagEventErrorResponse(eNO_ERROR_INFO);
853     LOG_STATUS_IF_ERRORED(l_eStatus, "sendDiagEventErrorResponse(eNO_ERROR_INFO)");
854   }
855   if (m_errorEventNtfData.isNeedReboot == TRUE) {
856     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
857            "System will reboot soon, so stop logging function.");
858     StopLoggingFunction(f_hApp);
859   }
860   m_bIsPrevEventCompleted = true;
861   l_eStatus = SendLogCompleteRequestToSystemManager(eFrameworkunifiedStatusOK);
862
863   l_eStatus = m_loggerCanEvent.PublishErrorEvent(f_hApp, m_errorEventNtfData,
864   TRUE,
865                                                  m_currentEventTriggerNumber,
866                                                  m_time);
867   LOG_STATUS_IF_ERRORED(l_eStatus, "m_loggerCanEvent.PublishErrorEvent();");
868
869   LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogCompleteRequestToSystemManager()");
870   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
871   return (l_eStatus);
872 }
873
874 EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode) {
875   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
876   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
877   if (this->m_ServiceName.length() > 0) {
878     l_eStatus = sendDiagEventErrorResponse(f_errCode, this->m_ServiceName);
879     this->m_ServiceName = "";
880   }
881
882   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
883   return (l_eStatus);
884 }
885
886 EFrameworkunifiedStatus CErrorEvent::sendDiagEventErrorResponse(EELL_ErrorCode f_errCode,
887                                                    std::string f_destName) {
888   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
889   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
890
891   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP, sizeof(EELL_ErrorCode), &f_errCode))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.  // NOLINT[whitespace/line_length]
892     // LCOV_EXCL_START 4: NSFW error case.
893     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
894     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
895            "SS_LOGGERCOPYEMERGENCYLOGS_ERROR_RESP Msg send failed = %x",
896            l_eStatus);
897     // LCOV_EXCL_STOP
898   }
899
900   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
901   return (l_eStatus);
902 }
903
904 EFrameworkunifiedStatus CErrorEvent::sendDiagEventResponse(void) {
905   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
906   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
907
908   if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(m_diagsessionhandle, SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP, 0, NULL))) {
909     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
910            "SS_LOGGERCOPYEMERGENCYLOGS_SUCCESS_RESP Msg send failed = %x",
911            l_eStatus);
912   }
913
914   m_ServiceName = "";
915
916   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
917   return (l_eStatus);
918 }
919
920 EFrameworkunifiedStatus CErrorEvent::SetDiagEventSourceName(std::string f_serviceName) {
921   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
922   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
923   if ((f_serviceName.length() > 0)
924       && (this->m_ServiceName.length() == 0)) {
925     this->m_ServiceName = f_serviceName;
926     l_eStatus = eFrameworkunifiedStatusOK;
927   } else {
928     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
929            " Error. f_serviceName(%s), m_serviceName(%s)",
930            f_serviceName.c_str(), m_ServiceName.c_str());
931   }
932
933   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
934   return (l_eStatus);
935 }
936
937 void CErrorEvent::SetDiagSessionHandle(HANDLE f_sessionhandle) {
938   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
939
940   m_diagsessionhandle = f_sessionhandle;
941
942   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
943 }
944
945 void CErrorEvent::SetMileage(UI_32 f_mileage) {
946   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
947   this->m_loggerUtil.SetMilage(f_mileage);
948   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
949 }
950
951 // LCOV_EXCL_START 200: 
952 EFrameworkunifiedStatus CErrorEvent::SaveNaviLog(EPWR_SHUTDOWN_TRIGGER_TYPE errType) {
953   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
954   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
955   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
956   UI_32 l_logMaxNum = 0;
957   std::string l_Filename = "";
958
959   uint32_t l_time;
960   uint8_t status;
961   Clock_getSystemTimeY2K38(&l_time, &status);
962   l_eStatus = m_loggerUtil.getEmmcNaviLogParams(l_time, errType, l_Filename,
963                                                 l_logMaxNum);
964
965   if (eFrameworkunifiedStatusOK != l_eStatus) {
966     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
967            " Error: getEmmcNaviLogParams NaviLog update failed %d", l_eStatus);
968   } else {
969     if (l_logMaxNum == 0) {
970       /*OutputNaviLogNmlMax or OutputNaviLogErrMax = 0. */
971       FRAMEWORKUNIFIEDLOG(
972           ZONE_WARN,
973           __FUNCTION__,
974           " Warning: Not update NaviLog. OutputNaviLogNmlMax or OutputNaviLogErrMax = 0");
975     } else {
976       FILE *fp;
977       void *p;
978       p = EL_mem_exram_mmap_simple(EL_MEM_ID_NAVI_LOG, PROT_READ | PROT_WRITE,
979       MAP_SHARED,
980                                    EL_MEM_CACHE_INVALID);
981       if (p == MAP_FAILED) {
982         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
983                "Error : EL_mem_exram_mmap_simple MAP_FAILD");
984         l_eStatus = eFrameworkunifiedStatusFail;
985       } else {
986         fp = fopen(l_Filename.c_str(), "wb");
987         if (fp == NULL) {
988           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open file %s",
989                  l_Filename.c_str());
990           l_eStatus = eFrameworkunifiedStatusAccessError;
991         } else {
992           fwrite(p, sizeof(unsigned char), EL_mem_getLength(EL_MEM_ID_NAVI_LOG),
993                  fp);
994           fclose(fp);
995         }
996         if (0 != EL_mem_exram_munmap(p, EL_mem_getLength(EL_MEM_ID_NAVI_LOG))) {
997           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : EL_mem_exram_munmap");
998         }
999       }
1000     }
1001   }
1002
1003   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1004   return (l_eStatus);
1005 }
1006 // LCOV_EXCL_STOP
1007
1008 EFrameworkunifiedStatus CErrorEvent::VerifyExtStorage(TLoggerErrorEvent event) {
1009   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1010   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
1011   std::string f_path;
1012
1013   f_path = m_pLoggerCfg->getUsb0MountPath();
1014
1015   if (eFrameworkunifiedStatusOK == l_eStatus) {
1016     l_eStatus = eFrameworkunifiedStatusFail;
1017
1018     if (eFrameworkunifiedStatusFail == l_eStatus) {
1019       // timeout or error
1020       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : get secure log failed or timeout");
1021     }
1022   } else {
1023     // timeout
1024     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error : ticket verify timeout.");
1025   }
1026
1027   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1028   return (l_eStatus);
1029 }
1030
1031 bool CErrorEvent::IsNeedVerify(EErrorEventType type) {
1032   bool ret = false;
1033   switch (type) {
1034     case eErrorEventTypeUserInvokedCollectScreenShot:
1035     case eErrorEventTypeUserInvokedCollectAllLogs:
1036     case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
1037     case eErrorEventTypeInterfaceunifiedEmmcLogs:
1038     case eErrorEventTypeEelExport:
1039     case eErrorEventTypeDiagEvent:
1040     case eErrorEventTypeCanEvent:
1041       ret = true;
1042       break;
1043     default:
1044       break;
1045   }
1046   return ret;
1047 }