3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
25 #include <sync_agent.h>
28 #include "common/dm_common.h"
29 #include "common/util/util.h"
30 #include "ipc_agent.h"
31 #include "ipc_common.h"
33 #ifndef OMADM_AGENT_LOG
35 #define LOG_TAG "OMA_DM_UTIL"
38 static void _update_csc();
40 void str_free(char **str)
55 int chartoint(char *data, int *value)
59 retvm_if(data == NULL, 0, "data is NULL!!");
65 (*value) = atoi(data);
74 int launch_oma_dm_fumo_ui()
79 _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
80 _DEBUG_INFO("\n is launch oma fumo dm ui : %d ?\n", result);
81 result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
82 _DEBUG_INFO("\n Is launch oma fumo dm ui , result : %d\n", result);
83 _DEBUG_INFO("\n---------------------------------------------------: %d \n", result);
86 bundle *pBundle = NULL;
87 pBundle = bundle_create();
88 if (pBundle == NULL) {
89 _DEBUG_INFO("bundle_create fail\n");
93 result = bundle_add(pBundle, "FOTA_UI", "3");
96 _DEBUG_INFO("bundle_add fail\n");
101 result = aul_launch_app(OMA_DM_FUMO_UI_PKG, pBundle);
102 _DEBUG_INFO("result : %d\n", result);
104 bundle_free(pBundle);
108 bundle_free(pBundle);
111 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
112 _DEBUG_INFO("existed oma dm ui\n");
113 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
119 int launch_om_dm_fumo_noti_ui(int noti_data, char *session_id, char *server_id)
124 _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
125 _DEBUG_INFO("\n is launch oma noti dm ui ? : %d\n", result);
126 result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
127 _DEBUG_INFO("\n Is launch oma noti dm ui , result : %d\n", result);
128 _DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
131 char *noti_type = NULL;
132 noti_type = g_strdup_printf("%d", noti_data);
134 bundle *pBundle = NULL;
135 pBundle = bundle_create();
136 if (pBundle == NULL) {
137 _DEBUG_INFO("bundle_create fail\n");
142 result = bundle_add(pBundle, "FOTA_NOTI", noti_type);
143 result = bundle_add(pBundle, "FOTA_SESSIONID", session_id);
144 result = bundle_add(pBundle, "FOTA_SERVERID", server_id);
146 if (session_id == NULL) {
147 /*if engine stoped by battery off or other exceptions */
148 result = bundle_add(pBundle, "FOTA_SESSIONID", "1111");
150 if (server_id == NULL) {
151 result = bundle_add(pBundle, "FOTA_SERVERID", "1111");
154 _DEBUG_INFO("bundle_add fail\n");
155 bundle_free(pBundle);
160 result = aul_launch_app(OMA_DM_FUMO_NOTI_UI_PKG, pBundle);
161 _DEBUG_INFO("result : %d\n", result);
164 bundle_free(pBundle);
169 str_free(¬i_type);
170 bundle_free(pBundle);
173 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
174 _DEBUG_INFO("existed oma dm noti ui\n");
175 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
181 int launch_om_dm_fumo_alert_ui()
186 _DEBUG_INFO("OMA_DM_ALERT_UI_PKG : %s", OMA_DM_ALERT_UI_PKG);
187 ret = aul_app_is_running(OMA_DM_ALERT_UI_PKG);
188 _DEBUG_INFO("aul_app_is_running(%s) [%d] ", OMA_DM_ALERT_UI_PKG, ret);
190 bundle *b = bundle_create();
191 //appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
192 //appsvc_set_pkgname(b, OMA_DM_ALERT_UI_PKG);
194 //ret = appsvc_run_service(b, 0, NULL, NULL);
195 ret = aul_launch_app(OMA_DM_ALERT_UI_PKG, b);
196 _DEBUG_INFO("result : %d\n", ret);
198 _DEBUG_INFO("oma dm alert ui run : %d\n", ret);
215 int launch_oma_dm_cp_ui(int sec_type, int ext_id)
219 _DEBUG_INFO("Start !!");
221 _DEBUG_INFO("OMA_DM_CP_UI_PKG : %s", OMA_DM_CP_UI_PKG);
222 _DEBUG_INFO("\n---------------------------------------------------\n");
223 _DEBUG_INFO("\n is launch oma dm cp ui ?\n");
224 result = aul_app_is_running(OMA_DM_CP_UI_PKG);
225 _DEBUG_INFO("\n Is launch oma dm cp ui, result : %d\n", result);
226 _DEBUG_INFO("\n---------------------------------------------------\n");
229 char *pin_type = NULL;
230 pin_type = g_strdup_printf("%d", sec_type);
232 extId = g_strdup_printf("%d", ext_id);
234 bundle *pBundle = NULL;
235 pBundle = bundle_create();
236 if (pBundle == NULL) {
237 _DEBUG_INFO("bundle_create fail\n");
242 result = bundle_add(pBundle, "PIN_TYPE", pin_type);
244 _DEBUG_INFO("bundle_add fail\n");
245 bundle_free(pBundle);
250 result = bundle_add(pBundle, "EXT_ID", extId);
252 _DEBUG_INFO("bundle_add fail\n");
253 bundle_free(pBundle);
258 result = aul_launch_app(OMA_DM_CP_UI_PKG, pBundle);
259 _DEBUG_INFO("result : %d\n", result);
263 bundle_free(pBundle);
268 bundle_free(pBundle);
271 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
272 _DEBUG_INFO("existed oma dm cp ui\n");
273 _DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
279 void terminate_oma_dm_ui(int result_status, ENGINE_ID service_engine_id)
283 if (result_status == DM_ERR_REMINDER_INTERVAL || result_status == DM_DOWNLOAD_POPUP || result_status == DM_INSTALL_POPUP || result_status == DM_RESUME_IDLE) {
284 _DEBUG_INFO("result status : %d", result_status);
288 _DEBUG_INFO("start");
290 DM_ERROR ret = DM_OK;
291 int isfumo_engine = 0;
292 engine_status *status = NULL;
294 bool cancel_flag = 0;
296 cancel_flag = sync_agent_check_cancel_flag();
301 isfumo_engine = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
303 if (isfumo_engine == 1) {
304 if (service_engine_id == FUMO_SERVICE_ENGINE) {
305 _DEBUG_INFO("existed engine id in db");
306 ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
307 _DEBUG_INFO("get fumo service engine : %d", ret);
309 if (status != NULL && status->ui_mode != NULL) {
310 result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
312 terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
314 result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
316 terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
319 _DEBUG_INFO("fumo service ui mode not existed");
323 Free_Memory_Engine_Status(&status, 1);
325 ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
326 _DEBUG_INFO("delete engine status : %d", ret);
328 _DEBUG_INFO("fumo service not existed");
331 _DEBUG_INFO("fumo service not existed");
337 void terminate_ui_status(int noti_type, char *ui_mode, int result_status)
343 _DEBUG_INFO("noti type : %d", noti_type);
344 /*noti_res = noti_engine_fail(noti_type, fail_type); */
347 case NOTI_ENGINE_START:
348 _DEBUG_INFO("connect to sever ui ");
349 if (result_status != DM_OK) {
350 if (result_status == DM_ERR_UNAUTHORIZED || result_status == DM_ERR_AUTHENTICATION_REQUIRED) {
351 noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE_AUTHENTICATION);
353 noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE);
356 noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_UPTODATA);
358 _DEBUG_INFO("connect to sever ui : %d", noti_res);
362 case NOTI_DOWNLOAD_INFO:
364 //case NOTI_WIFI_ONLY_DOWNLOAD_FAIL:
365 //case NOTI_MEMORY_FULL:
366 noti_res = noti_engine_fail(noti_type, 0);
368 case NOTI_LOW_BATTERY:
369 case NOTI_ALERT_DISPLAY:
370 case NOTI_ALERT_CONFIRMATION:
371 case NOTI_ALERT_INPUTTEXT:
372 case NOTI_ALERT_SINGLE_CHOICE:
373 case NOTI_ALERT_MULTIPLE_CHOICE:
379 _DEBUG_INFO("cancel ui : %d", noti_res);
390 /*FIXME(temporary do not process csc for ui reason)
391 check csc_check file is existed
392 if false do csc update
393 if true check csc xml file has been changed */
395 /*exist = sync_agent_is_existing_fs(CSC_CHECK_PATH); */
406 _DEBUG_INFO("update = %d", exist);
411 static void _update_csc()
416 /*sync_agent_write_whole_file(OMA_DS_CSC_CHECK_PATH, contents, strlen(contents), false); */
425 sync_agent_na_result_e ret = SYNC_AGENT_NA_SUCCESS;
426 sync_agent_na_network_connection_type_e con_type = SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_UNKNOWN;
427 sync_agent_na_network_connection_state_e con_state = SYNC_AGENT_NA_NETWORK_CONNECTION_STATE_NONE;
429 ret = sync_agent_get_connection_type(&con_type);
430 if (ret != SYNC_AGENT_NA_SUCCESS) {
431 _DEBUG_INFO("get connection type");
432 ret = SYNC_AGENT_NA_DOWNLOAD_DATA_FAIL;
435 _DEBUG_INFO("get connection type : %d", con_type);
437 ret = sync_agent_get_connection_state(&con_state);
438 _DEBUG_INFO("get connection state : %d", con_state);
439 if (ret != SYNC_AGENT_NA_SUCCESS) {
440 _DEBUG_INFO("get connection state");
441 ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
445 if (con_type != SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_WIFI || (con_type == SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_WIFI && con_state != SYNC_AGENT_NA_NETWORK_CONNECTION_STATE_WIFI_CONNECTED)) {
446 _DEBUG_INFO("wifi only on mode download fail");
447 ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
450 _DEBUG_INFO("wifi on mode download");
457 _DEBUG_INFO("error end %d : ", ret);
463 DM_ERROR nonce_decode(char *nextNonce, unsigned char **nextNonceDecode, unsigned int *out_len)
467 unsigned char *tempnextNonceDecode = NULL;
468 tempnextNonceDecode = g_base64_decode(nextNonce, (unsigned int *)(out_len));
470 if (tempnextNonceDecode == NULL && *out_len != 0) {
471 _DEBUG_INFO("tempnextNonceDecode = NULL , out len : %d", *out_len);
474 *nextNonceDecode = (unsigned char *)calloc(1, (*out_len) + 1);
475 for (i = 0; i < (*out_len); ++i) {
476 g_strlcat((char *)(*nextNonceDecode), zero, *out_len);
481 _DEBUG_INFO("tempnextNonceDecode = %s, out_len = %d", tempnextNonceDecode, *out_len);
482 /**nextNonceDecode = (char *)strdup(tempnextNonceDecode);
483 str_free((char **)(&tempnextNonceDecode));*/
484 *nextNonceDecode = tempnextNonceDecode;