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