tizen 2.3 release
[framework/pim/account-parser.git] / src / account.c
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 #include <glib.h>
18 #include <dlog.h>
19 #include <errno.h>
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
22 #include <account.h>
23 #include <account-types.h>
24 #include <pkgmgr-info.h>
25 #include <app_manager.h>
26
27 #include "account-dlog.h"
28
29 /* Define EXPORT_API */
30 #ifndef EXPORT_API
31 #define EXPORT_API __attribute__((visibility("default")))
32 #endif
33
34
35 static const xmlChar _NODE_ACCOUNT_PROVIDER[]                           = "account-provider";
36 static const xmlChar _NODE_ICON[]                                                       = "icon";
37 static const xmlChar _NODE_LABEL[]                                                      = "label";
38 static const xmlChar _NODE_CAPABILITY[]                                         = "capability";
39
40 static const xmlChar _ATTRIBUTE_APP_ID[]                                        = "appid";
41 static const xmlChar _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT[]     = "multiple-accounts-support";
42 static const xmlChar _ATTRIBUTE_SECTION[]                                       = "section";
43 static const xmlChar _ATTRIBUTE_TYPE[]                                          = "type";
44 static const xmlChar _ATTRIBUTE_XML_LANG[]                                      = "xml:lang";
45
46 static const xmlChar _VALUE_TRUE[]                                                      = "true";
47 static const xmlChar _VALUE_ACCOUNT[]                                           = "account";
48 static const xmlChar _VALUE_ACCOUNT_SMALL[]                                     = "account-small";
49 static const xmlChar _VALUE_XHIGH[]                                                     = "Xhigh";
50
51 static const char _DEFAULT_LOCALE[]                                                     = "default";
52
53 static char __old_account_provider_app_id[1024];
54
55 bool _on_account_received_cb(account_h account, void* user_data)
56 {
57         ENTER();
58         retvm_if((account == NULL) || (user_data == NULL), false, "A system error has occurred.");
59
60         char* account_provider_app_id = (char*)user_data;
61         retvm_if(account_provider_app_id == NULL, false, "account_provider_app_id is NULL.");
62
63         // Get the account ID
64         int account_db_id = 0;
65         int ret = account_get_account_id(account, &account_db_id);
66         retvm_if(ret != ACCOUNT_ERROR_NONE, false, "[%d] Failed to perform account_get_account_id().", ret);
67
68         ret = account_set_package_name(account, account_provider_app_id);
69         retvm_if(ret != ACCOUNT_ERROR_NONE, false, "[%d] Failed  to perform account_set_package_name().", ret);
70
71         // Update the account
72         ret = account_update_to_db_by_id_ex(account, account_db_id);
73         retvm_if(ret == ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, false, "[%d] The application does not register the account provider.", ret);
74         retvm_if(ret == ACCOUNT_ERROR_PERMISSION_DENIED, false, "[%d] The application has no permission to update this account.", ret);
75         retvm_if(ret == ACCOUNT_ERROR_RECORD_NOT_FOUND, false, "[%d] The account does not exist.", ret);
76         retvm_if(ret != ACCOUNT_ERROR_NONE, false, "[%d] Failed to perform account_update_to_db_by_id_ex().", ret);
77
78         return true;
79 }
80
81 int _register_account_provider(xmlDocPtr docPtr, char* account_provider_app_id)
82 {
83         ENTER();
84         _D("Registering the Account Provider.");
85
86         int ret = account_connect();
87         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]A system error has occurred.", ret);
88
89         int ret2 = 0;
90
91         account_type_h account_type_handle = NULL;
92         ret = account_type_create(&account_type_handle);
93         if(ret != ACCOUNT_ERROR_NONE || account_type_handle == NULL) {
94                 _E("[%d]Memory allocation failed.", ret);
95                 return ret;
96         }
97
98         // Node: <account>
99         xmlNodePtr cur_ptr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
100         if(cur_ptr == NULL) {
101                 ret = -1;
102                 _E("Failed to get the element.");
103                 goto CATCH;
104         }
105
106         _SECURE_D("Node: %s", cur_ptr->name);
107
108         // Get the children nodes
109         cur_ptr = cur_ptr->xmlChildrenNode;
110         if(cur_ptr == NULL) {
111                 ret = -1;
112                 _E("Failed to get the child element.");
113                 goto CATCH;
114         }
115
116         while(cur_ptr != NULL) {
117                 _SECURE_D("Node: %s", cur_ptr->name);
118
119                 // Node: <account-provider>
120                 if((!xmlStrcmp(cur_ptr->name, _NODE_ACCOUNT_PROVIDER))) {
121                         // Attribute: appid
122                         xmlChar* attribute_app_id = xmlGetProp(cur_ptr, _ATTRIBUTE_APP_ID);
123                         if(attribute_app_id == NULL) {
124                                 ret = -1;
125                                 _E("Failed to get the attribute.");
126                                 goto CATCH;
127                         }
128
129                         _SECURE_D("Attribute: appid - %s", attribute_app_id);
130
131                         ret = account_type_set_app_id(account_type_handle, (char*)attribute_app_id);
132                         if(ret != ACCOUNT_ERROR_NONE) {
133                                 _E("Failed to set the app ID.");
134                                 goto CATCH;
135                         }
136
137                         // Attribute: multiple-accounts-support
138                         xmlChar* multiple_accounts_support = xmlGetProp(cur_ptr, _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT);
139                         if(multiple_accounts_support == NULL) {
140                                 ret = -1;
141                                 _E("Failed to get the attribute.");
142                                 goto CATCH;
143                         }
144
145                         _SECURE_D("Attribute: multiple-accounts-support - %s", multiple_accounts_support);
146
147                         if((!xmlStrcmp(multiple_accounts_support, _VALUE_TRUE))) {
148                                 ret = account_type_set_multiple_account_support(account_type_handle, true);
149                                 if(ret != ACCOUNT_ERROR_NONE) {
150                                         _E("Failed to set the multiple accounts support.");
151                                         goto CATCH;
152                                 }
153                         } else {
154                                 ret = account_type_set_multiple_account_support(account_type_handle, false);
155                                 if (ret != ACCOUNT_ERROR_NONE)
156                                 {
157                                         _E("Failed to set the multiple accounts support.");
158                                         goto CATCH;
159                                 }
160                         }
161
162                         // Get the children nodes
163                         cur_ptr = cur_ptr->xmlChildrenNode;
164                         if(cur_ptr == NULL) {
165                                 ret = -1;
166                                 _E("Failed to get the child element.");
167                                 goto CATCH;
168                         }
169
170                         while(cur_ptr != NULL) {
171                                 _SECURE_D("Node: %s", cur_ptr->name);
172
173                                 // Node: <icon>
174                                 if((!xmlStrcmp(cur_ptr->name, _NODE_ICON))) {
175                                         // Attribute: section
176                                         xmlChar* section = xmlGetProp(cur_ptr, _ATTRIBUTE_SECTION);
177                                         if(section == NULL) {
178                                                 ret = -1;
179                                                 _E("Failed to get the attribute.");
180                                                 goto CATCH;
181                                         }
182
183                                         _SECURE_D("Attribute: section - %s", section);
184
185                                         char *resource_path = NULL;
186                                         if((!xmlStrcmp(section, _VALUE_ACCOUNT))) {
187                                                 xmlChar* account_icon = xmlNodeListGetString(docPtr, cur_ptr->xmlChildrenNode, 1);
188                                                 if(account_icon == NULL) {
189                                                         ret = -1;
190                                                         _E("Failed to get the value.");
191                                                         goto CATCH;
192                                                 }
193
194                                                 _SECURE_D("Node: icon - %s", account_icon);
195
196                                                 if (!strncmp(account_icon, "/usr/share/icons", 16)) {
197                                                         ret = account_type_set_icon_path(account_type_handle, (char*)account_icon);
198                                                         if(ret != ACCOUNT_ERROR_NONE) {
199                                                                 _E("Failed to set the icon path.");
200                                                                 goto CATCH;
201                                                         }
202                                                 } else {
203                                                         if (!strcmp(attribute_app_id, "com.samsung.samsungaccount")) {
204                                                                 char *icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.samsungaccount/shared/res/", (char*)account_icon);
205                                                                 if(icon_path == NULL) {
206                                                                         _E("icon_path is NULL.");
207                                                                         free(resource_path);
208                                                                         goto CATCH;
209                                                                 }
210
211                                                                 _D("icon_path[%s]", icon_path);
212                                                                 ret = account_type_set_icon_path(account_type_handle, icon_path);
213                                                                 if(ret != ACCOUNT_ERROR_NONE) {
214                                                                         _E("Failed to set the icon path.");
215                                                                         g_free(icon_path);
216                                                                         goto CATCH;
217                                                                 }
218                                                                 g_free(icon_path);
219                                                         } else if (!strcmp(attribute_app_id, "com.samsung.tizenaccount")) {
220                                                                 char *icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.tizenaccount/shared/res/", (char*)account_icon);
221                                                                 if(icon_path == NULL) {
222                                                                         _E("icon_path is NULL.");
223                                                                         free(resource_path);
224                                                                         goto CATCH;
225                                                                 }
226
227                                                                 _D("icon_path[%s]", icon_path);
228                                                                 ret = account_type_set_icon_path(account_type_handle, icon_path);
229                                                                 if(ret != ACCOUNT_ERROR_NONE) {
230                                                                         _E("Failed to set the icon path.");
231                                                                         g_free(icon_path);
232                                                                         goto CATCH;
233                                                                 }
234                                                                 g_free(icon_path);
235                                                         } else {
236                                                                 ret = app_manager_get_shared_resource_path((char*)attribute_app_id, &resource_path);
237                                                                 if(ret != APP_MANAGER_ERROR_NONE) {
238                                                                         _E("Failed to get the shared resource path.");
239                                                                         goto CATCH;
240                                                                 }
241
242                                                                 char *icon_path = g_strdup_printf("%s%s", resource_path, (char*)account_icon);
243                                                                 if(icon_path == NULL) {
244                                                                         _E("icon_path is NULL.");
245                                                                         free(resource_path);
246                                                                         goto CATCH;
247                                                                 }
248
249                                                                 free(resource_path);
250
251                                                                 _D("icon_path[%s]", icon_path);
252                                                                 ret = account_type_set_icon_path(account_type_handle, icon_path);
253                                                                 if(ret != ACCOUNT_ERROR_NONE) {
254                                                                         _E("Failed to set the icon path.");
255                                                                         g_free(icon_path);
256                                                                         goto CATCH;
257                                                                 }
258                                                                 g_free(icon_path);
259                                                         }
260                                                 }
261                                         } else if((!xmlStrcmp(section, _VALUE_ACCOUNT_SMALL))) {
262                                                 xmlChar* account_small_icon = xmlNodeListGetString(docPtr, cur_ptr->xmlChildrenNode, 1);
263                                                 if(account_small_icon == NULL) {
264                                                         ret = -1;
265                                                         _E("Failed to get the value.");
266                                                         goto CATCH;
267                                                 }
268
269                                                 _SECURE_D("Node: icon (small) - %s",  account_small_icon);
270
271                                                 if (!strncmp(account_small_icon, "/usr/share/icons", 16) || !strcmp(account_small_icon, "/usr/apps/com.samsung.tizenaccount/shared/res/TizenAccount.png")) {
272                                                         ret = account_type_set_small_icon_path(account_type_handle, (char*)account_small_icon);
273                                                         if(ret != ACCOUNT_ERROR_NONE) {
274                                                                 _E("Failed to set the small icon path.");
275                                                                 goto CATCH;
276                                                         }
277                                                 } else {
278                                                         if (!strcmp(attribute_app_id, "com.samsung.samsungaccount")) {
279                                                                 char *small_icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.samsungaccount/shared/res/", (char*)account_small_icon);
280                                                                 if(small_icon_path == NULL) {
281                                                                         _E("small_icon_path is NULL.");
282                                                                         free(resource_path);
283                                                                         goto CATCH;
284                                                                 }
285
286                                                                 _D("small_icon_path[%s]", small_icon_path);
287                                                                 ret = account_type_set_small_icon_path(account_type_handle, (char*)small_icon_path);
288                                                                 if(ret != ACCOUNT_ERROR_NONE) {
289                                                                         _E("Failed to set the small icon path.");
290                                                                         g_free(small_icon_path);
291                                                                         goto CATCH;
292                                                                 }
293                                                                 g_free(small_icon_path);
294                                                         } else {
295                                                                 ret = app_manager_get_shared_resource_path((char*)attribute_app_id, &resource_path);
296                                                                 if(ret != APP_MANAGER_ERROR_NONE) {
297                                                                         _E("Failed to get the shared resource path.");
298                                                                         goto CATCH;
299                                                                 }
300
301                                                                 char *small_icon_path = g_strdup_printf("%s%s", resource_path, (char*)account_small_icon);
302                                                                 if(small_icon_path == NULL) {
303                                                                         _E("small_icon_path is NULL.");
304                                                                         free(resource_path);
305                                                                         goto CATCH;
306                                                                 }
307
308                                                                 free(resource_path);
309
310                                                                 _D("small_icon_path[%s]", small_icon_path);
311                                                                 ret = account_type_set_small_icon_path(account_type_handle, (char*)small_icon_path);
312                                                                 if(ret != ACCOUNT_ERROR_NONE) {
313                                                                         _E("Failed to set the small icon path.");
314                                                                         g_free(small_icon_path);
315                                                                         goto CATCH;
316                                                                 }
317                                                                 g_free(small_icon_path);
318                                                         }
319                                                 }
320                                         }
321                                 } else if((!xmlStrcmp(cur_ptr->name, _NODE_LABEL))) {
322                                         // Node: <label>
323
324                                         _SECURE_D("Node: %s", cur_ptr->name);
325
326                                 // Attribute: xml:lang
327                                         xmlChar* xml_lang = xmlNodeGetLang(cur_ptr);
328                                         if(xml_lang != NULL) {
329                                                 _SECURE_D("Attribute: xml:lang - %s", xml_lang);
330
331                                                 char* lang = (char*)xml_lang;
332                                                 char* converted_lang = NULL;
333
334                                                 gchar** tokens = g_strsplit(lang, "-", 2);
335                                                 if(tokens == NULL) {
336                                                         ret = -1;
337                                                         _E("Failed to get token.");
338                                                         goto CATCH;
339                                                 }
340
341                                                 char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
342                                                 if(upper_token == NULL) {
343                                                         ret = -1;
344                                                         g_strfreev(tokens);
345                                                         _E("Failed to convert to upper case.");
346                                                         goto CATCH;
347                                                 }
348
349                                                 converted_lang = g_strdup_printf("%s_%s", tokens[0], upper_token);
350                                                 free(upper_token);
351
352                                                 if(converted_lang == NULL) {
353                                                         ret = -1;
354                                                         g_strfreev(tokens);
355                                                         _E("Failed to convert to upper case.");
356                                                         goto CATCH;
357                                                 }
358
359                                                 _SECURE_D("Attribute: converted lang - %s", converted_lang);
360
361                                                 g_strfreev(tokens);
362
363                                                 xmlChar* xml_label = xmlNodeListGetString(docPtr, cur_ptr->xmlChildrenNode, 1);
364                                                 if(xml_label == NULL) {
365                                                         ret = -1;
366                                                         g_free(converted_lang);
367                                                         _E("Failed to get the value.");
368                                                         goto CATCH;
369                                                 }
370
371                                                 _SECURE_D("Node: label - %s", xml_label);
372
373                                                 ret = account_type_set_label(account_type_handle, (char*)xml_label, converted_lang);
374                                                 if(ret != ACCOUNT_ERROR_NONE) {
375                                                         g_free(converted_lang);
376                                                         _E("[%d]Failed to set the display name.", ret);
377                                                         goto CATCH;
378                                                 }
379
380                                                 g_free(converted_lang);
381                                         } else {
382                                                 xmlChar* xml_label = xmlNodeListGetString(docPtr, cur_ptr->xmlChildrenNode, 1);
383                                                 if(xml_label == NULL) {
384                                                         ret = -1;
385                                                         _E("Failed to get the value.");
386                                                         goto CATCH;
387                                                 }
388
389                                                 _SECURE_D("Node: label - %s",  xml_label);
390
391                                                 ret = account_type_set_label(account_type_handle, (char*)xml_label, _DEFAULT_LOCALE);
392                                                 if(ret != ACCOUNT_ERROR_NONE) {
393                                                         _E("[%d]Failed to set the display name.", ret);
394                                                         goto CATCH;
395                                                 }
396                                         }
397                                 } else if((!xmlStrcmp(cur_ptr->name, _NODE_CAPABILITY))) {
398                                         // Node: <capability>
399
400                                         _SECURE_D("Node: %s", cur_ptr->name);
401
402                                         xmlChar* xml_capability = xmlNodeListGetString(docPtr, cur_ptr->xmlChildrenNode, 1);
403                                         if(xml_capability == NULL) {
404                                                 ret = -1;
405                                                 _E("Failed to get the value.");
406                                                 goto CATCH;
407                                         }
408
409                                         _SECURE_D("Node: capability - %s",  xml_capability);
410
411                                         ret = account_type_set_provider_feature(account_type_handle, (char*)xml_capability);
412                                         if(ret != ACCOUNT_ERROR_NONE) {
413                                                 _E("[%d]Failed to set the capability.", ret);
414                                                 goto CATCH;
415                                         }
416                                 }
417
418                                 cur_ptr = cur_ptr->next;
419                         }
420
421                         break;
422                 }
423
424                 cur_ptr = cur_ptr->next;
425         }
426
427         // Insert the account type to the account DB
428         {
429                 int account_type_db_id = 0;
430                 ret = account_type_insert_to_db(account_type_handle, &account_type_db_id);
431                 if(ret != ACCOUNT_ERROR_NONE) {
432                         _E("[%d]Failed to perform account_type_insert_to_db().", ret);
433                         goto CATCH;
434                 }
435         }
436
437         ret = account_type_destroy(account_type_handle);
438         if(ret != ACCOUNT_ERROR_NONE) {
439                 _E("[%d]Failed to perform account_type_destroy().", ret);
440                 goto CATCH;
441         }
442
443         ret = account_disconnect();
444         if(ret != ACCOUNT_ERROR_NONE) {
445                 _E("[%d]Failed to perform account_disconnect().", ret);
446                 goto CATCH;
447         }
448
449         return 0;
450
451 CATCH:
452         ret2 = account_type_destroy(account_type_handle);
453         retvm_if(ret2 != ACCOUNT_ERROR_NONE, ret2, "[%d]Failed to perform account_type_destroy().", ret2);
454
455         ret2 = account_disconnect();
456         retvm_if(ret2 != ACCOUNT_ERROR_NONE, ret2, "[%d]Failed to perform account_disconnect().", ret2);
457
458         return ret;
459 }
460
461 int _unregister_account_provider(pkgmgrinfo_appinfo_h package_info_handle, void* user_data)
462 {
463         ENTER();
464         _D("Unregistering the Account Provider.");
465
466         char* app_id = NULL;
467         pkgmgrinfo_appinfo_get_appid(package_info_handle, &app_id);
468         _D("appid : %s", app_id);
469
470         int ret = account_connect();
471         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to account_connect().", ret);
472
473         int ret2 = 0;
474
475         ret = account_delete_from_db_by_package_name((char*)app_id);
476         if((ret != ACCOUNT_ERROR_NONE) && (ret !=  ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
477                 _E("Failed to perform account_delete_from_db_by_package_name().");
478                 goto CATCH;
479         }
480
481         ret = account_type_delete_by_app_id((char*)app_id);
482         if(ret != ACCOUNT_ERROR_NONE) {
483                 _E("Failed to perform account_type_delete_by_app_id().");
484                 goto CATCH;
485         }
486
487         ret = account_disconnect();
488         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to account_disconnect().", ret);
489
490         return PMINFO_R_OK;
491
492 CATCH:
493         ret2 = account_disconnect();
494         retvm_if(ret2 != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to account_disconnect().", ret2);
495
496         return ret;
497 }
498
499 int _on_package_app_list_received_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
500 {
501         ENTER();
502         _D("Pkgmgr parser plugin pre upgrade.");
503
504         char* app_id = NULL;
505         pkgmgrinfo_appinfo_get_appid(handle, &app_id);
506         _D("appid : %s", app_id);
507
508         int ret = account_connect();
509         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to account_connect().", ret);
510
511         ret = account_type_delete_by_app_id((char*)app_id);
512         if(ret == ACCOUNT_ERROR_NONE) {
513                 _D("PKGMGR_PARSER_PLUGIN_PRE_UPGRADE: app ID - %s", app_id);
514                 strncpy(__old_account_provider_app_id, app_id, 128);
515
516                 return 0;
517         }
518
519         ret = account_disconnect();
520         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to account_disconnect().", ret);
521
522         return 0;
523 }
524
525 EXPORT_API
526 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
527 {
528         ENTER();
529         _D("PKGMGR_PARSER_PLUGIN_INSTALL");
530
531         char* account_provider_app_id = NULL;
532         int ret = _register_account_provider(docPtr, account_provider_app_id);
533         retvm_if(ret != 0, -1, "Failed to register the account provider.");
534
535         return 0;
536 }
537
538 EXPORT_API
539 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
540 {
541         ENTER();
542         _D("PKGMGR_PARSER_PLUGIN_UNINSTALL");
543
544         pkgmgrinfo_pkginfo_h package_info_handle = NULL;
545
546         int ret = pkgmgrinfo_pkginfo_get_pkginfo(packageId, &package_info_handle);
547         retvm_if(ret != PMINFO_R_OK, ret, "[%d]Failed to pkgmgrinfo_pkginfo_get_pkginfo().", ret);
548
549         ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_UI_APP, _unregister_account_provider, NULL);
550         if(ret != PMINFO_R_OK) {
551                 _D("Failed to get the application information list.");
552                 pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
553
554                 return -1;
555         }
556
557         pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
558         return 0;
559 }
560
561 EXPORT_API
562 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char* packageId)
563 {
564         ENTER();
565         _D("PKGMGR_PARSER_PLUGIN_PRE_UPGRADE");
566
567         memset(__old_account_provider_app_id, 0x00, sizeof(__old_account_provider_app_id));
568
569         pkgmgrinfo_pkginfo_h package_info_handle = NULL;
570
571         int ret = pkgmgrinfo_pkginfo_get_pkginfo(packageId, &package_info_handle);
572         retvm_if(ret != PMINFO_R_OK, ret, "[%d]Failed to pkgmgrinfo_pkginfo_get_pkginfo().", ret);
573
574         ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_UI_APP, _on_package_app_list_received_cb, NULL);
575         if(ret != PMINFO_R_OK) {
576                 _D("Failed to get the application information list.");
577                 pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
578
579                 return -1;
580         }
581
582         pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
583
584         return 0;
585 }
586
587 EXPORT_API
588 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char* packageId)
589 {
590         ENTER();
591         _D("PKGMGR_PARSER_PLUGIN_UPGRADE");
592
593         char* account_provider_app_id = NULL;
594         int ret = _register_account_provider(docPtr, account_provider_app_id);
595         retvm_if(ret != 0, ret, "[%d]Failed to register the account provider.", ret);
596
597         ret = account_connect();
598         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to perfrom account_connect().", ret);
599
600         int ret2 = 0;
601
602         ret = account_query_account_by_package_name(_on_account_received_cb, __old_account_provider_app_id, (void*)account_provider_app_id);
603         if((ret != ACCOUNT_ERROR_NONE) && (ret != ACCOUNT_ERROR_RECORD_NOT_FOUND)) {
604                 _E("Failed to perform account_query_account_by_package_name().");
605                 goto CATCH;
606         }
607
608         ret = account_disconnect();
609         retvm_if(ret != ACCOUNT_ERROR_NONE, ret, "[%d]Failed to perfrom account_disconnect().", ret);
610
611         return 0;
612
613 CATCH:
614         ret2 = account_disconnect();
615         retvm_if(ret2 != ACCOUNT_ERROR_NONE, ret2, "[%d]Failed to perfrom account_disconnect().", ret2);
616
617         return ret;
618 }