1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
/*
* oma-dm-agent
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*lib*/
#include <aul.h>
#include <unistd.h>
#include <appsvc.h>
#include <glib.h>
/*sync-agent*/
#include <sync_agent.h>
/*dm-agent*/
#include "common/dm_common.h"
#include "common/util/util.h"
#include "ipc_agent.h"
#include "ipc_common.h"
#ifndef OMADM_AGENT_LOG
#undef LOG_TAG
#define LOG_TAG "OMA_DM_UTIL"
#endif
static void _update_csc();
void str_free(char **str)
{
_EXTERN_FUNC_ENTER;
if (*str == NULL) {
_EXTERN_FUNC_EXIT;
return;
} else {
free(*str);
*str = NULL;
}
_EXTERN_FUNC_EXIT;
}
int chartoint(char *data, int *value)
{
_EXTERN_FUNC_ENTER;
retvm_if(data == NULL, 0, "data is NULL!!");
if (data == NULL) {
_EXTERN_FUNC_EXIT;
return 0;
} else {
(*value) = atoi(data);
_EXTERN_FUNC_EXIT;
return 1;
}
_EXTERN_FUNC_EXIT;
return 0;
}
int launch_oma_dm_fumo_ui()
{
_EXTERN_FUNC_ENTER;
int result = 0;
_DEBUG_INFO("\n---------------------------------------------------: %d\n", result);
_DEBUG_INFO("\n is launch oma fumo dm ui : %d ?\n", result);
result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
_DEBUG_INFO("\n Is launch oma fumo dm ui , result : %d\n", result);
_DEBUG_INFO("\n---------------------------------------------------: %d \n", result);
if (result == 0) {
bundle *pBundle = NULL;
pBundle = bundle_create();
if (pBundle == NULL) {
_DEBUG_INFO("bundle_create fail\n");
_EXTERN_FUNC_EXIT;
return 0;
}
result = bundle_add(pBundle, "FOTA_UI", "3");
if (result == -1) {
bundle_free(pBundle);
_DEBUG_INFO("bundle_add fail\n");
_EXTERN_FUNC_EXIT;
return 0;
}
result = aul_launch_app(OMA_DM_FUMO_UI_PKG, pBundle);
_DEBUG_INFO("result : %d\n", result);
if (result == -1) {
bundle_free(pBundle);
_EXTERN_FUNC_EXIT;
return 0;
}
bundle_free(pBundle);
sleep(2);
} else {
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
_DEBUG_INFO("existed oma dm ui\n");
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
}
_EXTERN_FUNC_EXIT;
return 1;
}
int launch_om_dm_fumo_noti_ui(int noti_data, char *session_id, char *server_id, int triger_type)
{
_EXTERN_FUNC_ENTER;
int result = 0;
_DEBUG_INFO("---------------------------------------------------: %d", result);
//_DEBUG_INFO(" is launch oma noti dm ui ? : %d", result);
//result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
_DEBUG_INFO(" Is launch oma noti dm ui , result : %d", result);
_DEBUG_INFO("---------------------------------------------------: %d", result);
_DEBUG_INFO(" triger_type [%d]", triger_type);
if (result == 0) {
char *noti_type = NULL;
noti_type = g_strdup_printf("%d", noti_data);
char *str_triger_type = NULL;
str_triger_type = g_strdup_printf("%d", triger_type);
bundle *pBundle = NULL;
pBundle = bundle_create();
if (pBundle == NULL) {
_DEBUG_INFO("bundle_create fail\n");
str_free(¬i_type);
str_free(&str_triger_type);
_EXTERN_FUNC_EXIT;
return 0;
}
result = bundle_add(pBundle, "FOTA_NOTI", noti_type);
if (session_id == NULL) {
/*if engine stoped by battery off or other exceptions */
result = bundle_add(pBundle, "FOTA_SESSIONID", "1111");
} else {
result = bundle_add(pBundle, "FOTA_SESSIONID", session_id);
}
if (server_id == NULL) {
result = bundle_add(pBundle, "FOTA_SERVERID", "1111");
//result = bundle_add(pBundle, "FOTA_SERVERID", "mform");
} else {
result = bundle_add(pBundle, "FOTA_SERVERID", server_id);
}
result = bundle_add(pBundle, "FOTA_TRIGERTYPE", str_triger_type);
if (result == -1) {
_DEBUG_INFO("bundle_add fail\n");
bundle_free(pBundle);
str_free(¬i_type);
str_free(&str_triger_type);
_EXTERN_FUNC_EXIT;
return 0;
}
result = aul_launch_app(OMA_DM_FUMO_NOTI_UI_PKG, pBundle);
_DEBUG_INFO("result : %d\n", result);
if (result == -1) {
bundle_free(pBundle);
str_free(¬i_type);
str_free(&str_triger_type);
_EXTERN_FUNC_EXIT;
return 0;
}
str_free(¬i_type);
str_free(&str_triger_type);
bundle_free(pBundle);
sleep(2);
} else {
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
_DEBUG_INFO("existed oma dm noti ui\n");
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
}
_EXTERN_FUNC_EXIT;
return 1;
}
int launch_om_dm_fumo_alert_ui()
{
_EXTERN_FUNC_ENTER;
int ret = 0;
_DEBUG_INFO("OMA_DM_ALERT_UI_PKG : %s", OMA_DM_ALERT_UI_PKG);
ret = aul_app_is_running(OMA_DM_ALERT_UI_PKG);
_DEBUG_INFO("aul_app_is_running(%s) [%d] ", OMA_DM_ALERT_UI_PKG, ret);
if (ret == 0) {
bundle *b = bundle_create();
//appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
//appsvc_set_pkgname(b, OMA_DM_ALERT_UI_PKG);
//ret = appsvc_run_service(b, 0, NULL, NULL);
ret = aul_launch_app(OMA_DM_ALERT_UI_PKG, b);
_DEBUG_INFO("result : %d\n", ret);
_DEBUG_INFO("oma dm alert ui run : %d\n", ret);
bundle_free(b);
if (ret >= 0) {
sleep(2);
_EXTERN_FUNC_EXIT;
return 1;
} else {
_EXTERN_FUNC_EXIT;
return 0;
}
} else {
return 1;
}
_EXTERN_FUNC_EXIT;
return 0;
}
int launch_oma_dm_cp_ui(int sec_type, int ext_id)
{
_EXTERN_FUNC_ENTER;
_DEBUG_INFO("Start !!");
int result = 0;
_DEBUG_INFO("OMA_DM_CP_UI_PKG : %s", OMA_DM_CP_UI_PKG);
_DEBUG_INFO("\n---------------------------------------------------\n");
_DEBUG_INFO("\n is launch oma dm cp ui ?\n");
result = aul_app_is_running(OMA_DM_CP_UI_PKG);
_DEBUG_INFO("\n Is launch oma dm cp ui, result : %d\n", result);
_DEBUG_INFO("\n---------------------------------------------------\n");
if (result == 0) {
char *pin_type = NULL;
pin_type = g_strdup_printf("%d", sec_type);
char *extId = NULL;
extId = g_strdup_printf("%d", ext_id);
bundle *pBundle = NULL;
pBundle = bundle_create();
if (pBundle == NULL) {
_DEBUG_INFO("bundle_create fail\n");
_EXTERN_FUNC_EXIT;
return 0;
}
result = bundle_add(pBundle, "PIN_TYPE", pin_type);
if (result == -1) {
_DEBUG_INFO("bundle_add fail\n");
bundle_free(pBundle);
_EXTERN_FUNC_EXIT;
return 0;
}
result = bundle_add(pBundle, "EXT_ID", extId);
if (result == -1) {
_DEBUG_INFO("bundle_add fail\n");
bundle_free(pBundle);
_EXTERN_FUNC_EXIT;
return 0;
}
result = aul_launch_app(OMA_DM_CP_UI_PKG, pBundle);
_DEBUG_INFO("result : %d\n", result);
if (result == -1) {
_EXTERN_FUNC_EXIT;
bundle_free(pBundle);
return 0;
}
str_free(&pin_type);
bundle_free(pBundle);
sleep(2);
} else {
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
_DEBUG_INFO("existed oma dm cp ui\n");
_DEBUG_INFO("---------------------------------------------------------------------------------------------------------------------------------");
}
_EXTERN_FUNC_EXIT;
return 1;
}
void terminate_oma_dm_ui(int result_status, ENGINE_ID service_engine_id)
{
_EXTERN_FUNC_ENTER;
if (result_status == DM_ERR_REMINDER_INTERVAL || result_status == DM_DOWNLOAD_POPUP || result_status == DM_INSTALL_POPUP || result_status == DM_RESUME_IDLE) {
_DEBUG_INFO("result status : %d", result_status);
return;
}
_DEBUG_INFO("start");
DM_ERROR ret = DM_OK;
int isfumo_engine = 0;
engine_status *status = NULL;
int result = 0;
bool cancel_flag = 0;
cancel_flag = sync_agent_check_cancel_flag();
if (cancel_flag) {
_EXTERN_FUNC_EXIT;
return;
}
isfumo_engine = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
if (isfumo_engine == 1) {
if (service_engine_id == FUMO_SERVICE_ENGINE) {
_DEBUG_INFO("existed engine id in db");
ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
_DEBUG_INFO("get fumo service engine : %d", ret);
if (status != NULL && status->ui_mode != NULL) {
result = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
if (result == 1) {
terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
}
result = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
if (result == 1) {
terminate_ui_status(status->ui_noti_type, status->ui_mode, result_status);
}
} else {
_DEBUG_INFO("fumo service ui mode not existed");
}
if (status != NULL)
Free_Memory_Engine_Status(&status, 1);
ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
_DEBUG_INFO("delete engine status : %d", ret);
} else {
_DEBUG_INFO("fumo service not existed");
}
} else {
_DEBUG_INFO("fumo service not existed");
}
_EXTERN_FUNC_EXIT;
}
void terminate_ui_status(int noti_type, char *ui_mode, int result_status)
{
_EXTERN_FUNC_ENTER;
int noti_res = 0;
_DEBUG_INFO("noti type : %d", noti_type);
/*noti_res = noti_engine_fail(noti_type, fail_type); */
switch (noti_type) {
case NOTI_ENGINE_START:
_DEBUG_INFO("connect to sever ui ");
if (result_status != DM_OK) {
if (result_status == DM_ERR_UNAUTHORIZED || result_status == DM_ERR_AUTHENTICATION_REQUIRED) {
noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE_AUTHENTICATION);
} else {
noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_FAILURE);
}
} else {
noti_res = noti_engine_fail(noti_type, CONNECTION_STATUS_UPTODATA);
}
_DEBUG_INFO("connect to sever ui : %d", noti_res);
break;
case NOTI_UNKNOWN:
case NOTI_DOWNLOAD:
case NOTI_DOWNLOAD_INFO:
case NOTI_INSTALL:
//case NOTI_WIFI_ONLY_DOWNLOAD_FAIL:
//case NOTI_MEMORY_FULL:
noti_res = noti_engine_fail(noti_type, 0);
break;
case NOTI_LOW_BATTERY:
case NOTI_ALERT_DISPLAY:
case NOTI_ALERT_CONFIRMATION:
case NOTI_ALERT_INPUTTEXT:
case NOTI_ALERT_SINGLE_CHOICE:
case NOTI_ALERT_MULTIPLE_CHOICE:
break;
default:
break;
}
_DEBUG_INFO("cancel ui : %d", noti_res);
_EXTERN_FUNC_EXIT;
}
int check_csc()
{
_EXTERN_FUNC_ENTER;
int exist = 0;
/*FIXME(temporary do not process csc for ui reason)
check csc_check file is existed
if false do csc update
if true check csc xml file has been changed */
/*exist = sync_agent_is_existing_fs(CSC_CHECK_PATH); */
/*temp value */
exist = 1;
/*for prevent*/
/*if(exist == 0 ) {
_update_csc();
} */
_update_csc();
_DEBUG_INFO("update = %d", exist);
_EXTERN_FUNC_EXIT;
return exist;
}
static void _update_csc()
{
_INNER_FUNC_ENTER;
//dmacc mo db update
/*sync_agent_write_whole_file(OMA_DS_CSC_CHECK_PATH, contents, strlen(contents), false); */
_INNER_FUNC_EXIT;
}
int get_wifi_state()
{
_EXTERN_FUNC_ENTER;
sync_agent_na_result_e ret = SYNC_AGENT_NA_SUCCESS;
sync_agent_na_network_connection_type_e con_type = SYNC_AGENT_NA_NETWORK_CONNECTION_TYPE_UNKNOWN;
sync_agent_na_network_connection_state_e con_state = SYNC_AGENT_NA_NETWORK_CONNECTION_STATE_NONE;
ret = sync_agent_get_connection_type(&con_type);
if (ret != SYNC_AGENT_NA_SUCCESS) {
_DEBUG_INFO("get connection type");
ret = SYNC_AGENT_NA_DOWNLOAD_DATA_FAIL;
goto return_part;
}
_DEBUG_INFO("get connection type : %d", con_type);
ret = sync_agent_get_connection_state(&con_state);
_DEBUG_INFO("get connection state : %d", con_state);
if (ret != SYNC_AGENT_NA_SUCCESS) {
_DEBUG_INFO("get connection state");
ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
goto return_part;
}
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)) {
_DEBUG_INFO("wifi only on mode download fail");
ret = SYNC_AGENT_NA_NETWORK_UNAVAILABLE;
goto return_part;
} else {
_DEBUG_INFO("wifi on mode download");
}
_EXTERN_FUNC_EXIT;
return ret;
return_part:
_DEBUG_INFO("error end %d : ", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR nonce_decode(char *nextNonce, unsigned char **nextNonceDecode, unsigned int *out_len)
{
_EXTERN_FUNC_ENTER;
unsigned char *tempnextNonceDecode = NULL;
tempnextNonceDecode = g_base64_decode(nextNonce, (unsigned int *)(out_len));
if (tempnextNonceDecode == NULL && *out_len != 0) {
_DEBUG_INFO("tempnextNonceDecode = NULL , out len : %d", *out_len);
int i = 0;
char *zero = "0";
*nextNonceDecode = (unsigned char *)calloc(1, (*out_len) + 1);
for (i = 0; i < (*out_len); ++i) {
g_strlcat((char *)(*nextNonceDecode), zero, *out_len);
}
} else {
_DEBUG_INFO("tempnextNonceDecode = %s, out_len = %d", tempnextNonceDecode, *out_len);
/**nextNonceDecode = (char *)strdup(tempnextNonceDecode);
str_free((char **)(&tempnextNonceDecode));*/
*nextNonceDecode = tempnextNonceDecode;
}
_EXTERN_FUNC_EXIT;
return DM_OK;
}
|