2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <native_service/ns_backup.h>
18 #include <agl_thread.h>
19 #include <system_service/ss_system_if.h>
20 #include <system_service/ss_system_manager_notifications.h>
21 #include <native_service/frameworkunified_multithreading.h>
28 #include "bkup_param.h"
29 #include "bkup_backupmanagerlog.h"
30 #include "bkup_process.h"
32 pthread_t g_work_thread_id = 0;
33 pthread_t g_delay_thread_id = 0;
34 pthread_t g_nand_thread_id = 0;
35 HANDLE g_msg_handle_thread = NULL;
37 typedef void (* signal_handler)(int);
39 void SignalHandlerFuncForMsgHandleThread(int signum) {
43 EFrameworkunifiedStatus MsgHandleThreadStart(HANDLE h_app) {
44 signal_handler p_signal = SignalHandlerFuncForMsgHandleThread;
45 signal(SIGUSR1, p_signal);
47 g_work_thread_id = pthread_self();
49 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
50 // LCOV_EXCL_BR_START 4: NSFW error case
51 if ((e_status = FrameworkunifiedAttachCallbackToDispatcher(h_app, FRAMEWORKUNIFIED_ANY_SOURCE, BACKUP_CID, BkupHandler)) != eFrameworkunifiedStatusOK) {
52 // LCOV_EXCL_BR_STOP 4: NSFW error case
53 // LCOV_EXCL_START 4: NSFW error case
54 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
55 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedAttachCallbacksToDispatcher e_status:%d\n", e_status);
57 // LCOV_EXCL_STOP 4: NSFW error case
63 EFrameworkunifiedStatus MsgHandleThreadStop(HANDLE h_app) {
64 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
68 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE h_app) {
69 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
70 pthread_attr_t t_attr;
73 // LCOV_EXCL_BR_START 4: NSFW error case
74 if ((e_status = FrameworkunifiedRegisterServiceAvailabilityNotification(h_app, NTFY_BackupMgr_Availability)) != eFrameworkunifiedStatusOK) {
75 // LCOV_EXCL_BR_STOP 4: NSFW error case
76 // LCOV_EXCL_START 4: NSFW error case
77 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
78 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedRegisterServiceAvailabilityNotification e_status:%d\n", e_status);
80 // LCOV_EXCL_STOP 4: NSFW error case
83 if (pthread_attr_init(&t_attr) < 0) { // LCOV_EXCL_BR_LINE 5:pthread_attr_init's error case.
84 // LCOV_EXCL_START 5:pthread_attr_init's error case.
85 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
86 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "pthread_attr_init:%s", strerror(errno));
88 // LCOV_EXCL_STOP 5:pthread_attr_init's error case.
91 // LCOV_EXCL_BR_START 5:pthread_attr_setinheritsched's error case.
92 if (pthread_attr_setinheritsched(&t_attr, PTHREAD_INHERIT_SCHED) < 0) {
93 // LCOV_EXCL_BR_STOP 5:pthread_attr_setinheritsched's error case.
94 // LCOV_EXCL_START 5:pthread_attr_setinheritsched's error case.
95 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
96 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "pthread_attr_setinheritsched:%s", strerror(errno));
98 // LCOV_EXCL_STOP 5:pthread_attr_setinheritsched's error case.
101 if (pthread_create(&t, &t_attr, BkupNandThread, NULL) < 0) { // LCOV_EXCL_BR_LINE 5:pthread_create's error case.
102 // LCOV_EXCL_START 5:pthread_create's error case.
103 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
104 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "pthread_create:%s", strerror(errno));
106 // LCOV_EXCL_STOP 5:pthread_create's error case.
109 if (pthread_create(&t, &t_attr, BkupDelayThread, NULL) < 0) { // LCOV_EXCL_BR_LINE 5:pthread_create's error case.
110 // LCOV_EXCL_START 5:pthread_create's error case.
111 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
112 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "pthread_create:%s", strerror(errno));
114 // LCOV_EXCL_STOP 5:pthread_create's error case.
118 if (e_status != eFrameworkunifiedStatusOK) {
119 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "InitNv e_status:%d", e_status);
123 if (BckupParamInit() < 0) { // LCOV_EXCL_BR_LINE 5:C API's error case.
124 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
125 exit(EXIT_FAILURE); // LCOV_EXCL_LINE 5:C API's error case.
128 // LCOV_EXCL_BR_START 4: NSFW error case
129 if ((e_status = FrameworkunifiedAttachCallbackToDispatcher(h_app, FRAMEWORKUNIFIED_ANY_SOURCE, BACKUP_CID, BkupHandler)) != eFrameworkunifiedStatusOK) {
130 // LCOV_EXCL_BR_STOP 4: NSFW error case
131 // LCOV_EXCL_START 4: NSFW error case
132 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
133 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedAttachCallbacksToDispatcher e_status:%d\n", e_status);
135 // LCOV_EXCL_STOP 4: NSFW error case
139 g_msg_handle_thread = FrameworkunifiedCreateChildThread(h_app, SERVICE_BACKUP_MANAGER_MSG_HANDLE_THREAD, MsgHandleThreadStart, MsgHandleThreadStop); // LCOV_EXCL_BR_LINE 11:Unexpected branch // NOLINT (whitespace/line_length)
140 if (g_msg_handle_thread == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
141 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
142 // LCOV_EXCL_START 4: NSFW error case.
143 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
144 "Fail to create SERVICE_BACKUP_MANAGER_MSG_HANDLE_THREAD");
145 // LCOV_EXCL_STOP 4: NSFW error case.
147 if (eFrameworkunifiedStatusOK != (e_status = FrameworkunifiedStartChildThread(h_app, g_msg_handle_thread, 0, NULL))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT (whitespace/line_length)
148 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
149 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to Start SERVICE_BACKUP_MANAGER_MSG_HANDLE_THREAD. Status:%#x", e_status); // LCOV_EXCL_LINE 4: NSFW error case. // NOLINT (whitespace/line_length)
153 // LCOV_EXCL_BR_START 4: NSFW error case
154 if ((e_status = FrameworkunifiedSubscribeNotificationWithCallback(h_app,
155 NTFY_SSSystemMgrPowerOnOff,
156 bkup_power_handler)) != eFrameworkunifiedStatusOK) {
157 // LCOV_EXCL_BR_STOP 4: NSFW error case
158 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
159 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedSubscribeNotificationWithCallback eStatus:%d", e_status); // LCOV_EXCL_LINE 4: NSFW error case. // NOLINT (whitespace/line_length)
162 e_status = BkupInitHandler(h_app); // LCOV_EXCL_BR_LINE 11:unexpected branch
164 // LCOV_EXCL_BR_START 4: NSFW error case
165 if ((e_status = FrameworkunifiedPublishServiceAvailability(h_app, TRUE)) != eFrameworkunifiedStatusOK) {
166 // LCOV_EXCL_BR_STOP 4: NSFW error case
167 // LCOV_EXCL_START 4: NSFW error case
168 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
169 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedPublishServiceAvailability e_status:%d\n", e_status);
171 // LCOV_EXCL_STOP 4: NSFW error case
177 // LCOV_EXCL_START 14 Resident process, not called by NSFW
178 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE h_app) {
179 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
180 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
181 return eFrameworkunifiedStatusOK;
183 // LCOV_EXCL_STOP 14 Resident process, not called by NSFW
185 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE h_app) {
186 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
187 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
188 // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h"
189 return eFrameworkunifiedStatusOK;
192 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE h_app) {
193 EFrameworkunifiedStatus e_status = BkupTerminateHandler(h_app);
195 if (FrameworkunifiedPublishServiceAvailability(h_app, FALSE) != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case
196 // LCOV_EXCL_START 15:marco defined in "native_service/ns_logger_if.h"
197 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
198 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedPublishServiceAvailability fail\n");
199 // LCOV_EXCL_STOP 15:marco defined in "native_service/ns_logger_if.h"
202 // LCOV_EXCL_BR_START 4: NSFW error case
203 if (eFrameworkunifiedStatusOK == (FrameworkunifiedStopChildThread(h_app, g_msg_handle_thread, 0, NULL))) {
204 // LCOV_EXCL_BR_STOP 4: NSFW error case
205 FrameworkunifiedDestroyChildThread(h_app, g_msg_handle_thread);
206 g_msg_handle_thread = NULL;
209 int ret2 = pthread_kill(g_work_thread_id, SIGUSR1);
211 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
212 "thread is already exit !");
213 } else if (EINVAL == ret2) {
214 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
215 "signal is invalid !");
217 pthread_join(g_work_thread_id, NULL);
220 ret2 = pthread_kill(g_nand_thread_id, SIGUSR1);
222 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
223 "thread is already exit !");
224 } else if (EINVAL == ret2) {
225 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
226 "signal is invalid !");
228 pthread_join(g_nand_thread_id, NULL);
231 ret2 = pthread_kill(g_delay_thread_id, SIGUSR1);
233 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
234 "thread is already exit !");
235 } else if (EINVAL == ret2) {
236 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __PRETTY_FUNCTION__,
237 "signal is invalid !");
239 pthread_join(g_delay_thread_id, NULL);
245 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp) {
246 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
247 return eFrameworkunifiedStatusOK;
250 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp) {
251 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
252 return eFrameworkunifiedStatusOK;
255 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp) {
256 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
257 return eFrameworkunifiedStatusOK;
260 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp) {
261 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
262 return eFrameworkunifiedStatusOK;
265 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE h_app) { // LCOV_EXCL_START 7:debug code
266 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
267 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
268 return eFrameworkunifiedStatusOK;
270 // LCOV_EXCL_STOP 7:debug code
272 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE h_app) { // LCOV_EXCL_START 7:debug code
273 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
274 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "called");
275 return eFrameworkunifiedStatusOK;
277 // LCOV_EXCL_STOP 7:debug code