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