d372654ab1d934701723cc30f4116753cd512cb9
[platform/framework/native/appfw.git] / src / app / package / FAppPkg_PackageAppInfoImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FAppPkg_PackageAppInfoImpl.cpp
19  * @brief       This is the implementation for the _PackageAppInfoImpl class.
20  */
21 #include <new>
22 #include <cstdio>
23 #include <cstdlib>
24 #include <unistd.h>
25 #include <unique_ptr.h>
26
27 #include <pkgmgr-info.h>
28
29 #include <FAppPkgPackageManager.h>
30 #include <FAppPkgPackageAppInfo.h>
31 #include <FBaseSysLog.h>
32 #include <FIoDatabase.h>
33 #include <FIoDbEnumerator.h>
34 #include <FIoDbStatement.h>
35 #include <FBase_StringConverter.h>
36
37 #include "FAppPkg_PackageManagerImpl.h"
38 #include "FApp_TemplateUtil.h"
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Io;
44
45 namespace Tizen { namespace App { namespace Package
46 {
47
48 const AppId&
49 _PackageAppInfoImpl::GetAppId(void) const
50 {
51         return __appId;
52 }
53
54 result
55 _PackageAppInfoImpl::SetAppId(const AppId& appId)
56 {
57         __appId = appId;
58         return E_SUCCESS;
59 }
60
61 const String&
62 _PackageAppInfoImpl::GetAppName(void) const
63 {
64         return __appName;
65 }
66
67 result
68 _PackageAppInfoImpl::SetAppName(const String& appName)
69 {
70         __appName = appName;
71         return E_SUCCESS;
72 }
73
74 const String&
75 _PackageAppInfoImpl::GetAppDisplayName(void) const
76 {
77         return __appDiplayName;
78 }
79
80 result
81 _PackageAppInfoImpl::SetAppDisplayName(const String& appDiplayName)
82 {
83         __appDiplayName = appDiplayName;
84         return E_SUCCESS;
85 }
86
87 const String&
88 _PackageAppInfoImpl::GetAppMenuIconPath(void) const
89 {
90         return __appIconPath;
91 }
92
93 result
94 _PackageAppInfoImpl::SetAppMenuIconPath(const String& iconPath)
95 {
96         __appIconPath = iconPath;
97         return E_SUCCESS;
98 }
99
100 const String&
101 _PackageAppInfoImpl::GetAppSettingIconPath(void) const
102 {
103         return __appSettingIconPath;
104 }
105
106 result
107 _PackageAppInfoImpl::SetAppSettingIconPath(const Tizen::Base::String& appSettingIcon)
108 {
109         __appSettingIconPath = appSettingIcon;
110         return E_SUCCESS;
111 }
112
113 const String&
114 _PackageAppInfoImpl::GetAppNotificationIconPath(void) const
115 {
116         return __appNotificationIconPath;
117 }
118
119 result
120 _PackageAppInfoImpl::SetAppNotificationIconPath(const String& notificationIconPath)
121 {
122         __appNotificationIconPath = notificationIconPath;
123         return E_SUCCESS;
124 }
125
126 Bitmap*
127 _PackageAppInfoImpl::GetAppMenuIconN(void) const
128 {
129         SysTryReturn(NID_APP, __appIconPath.IsEmpty() == false, null, E_FILE_NOT_FOUND, "appIconPath() is empty.");
130
131         return null;
132 }
133
134 HashMap*
135 _PackageAppInfoImpl::GetAppMetadataListN(void) const
136 {
137         HashMap* pMap = null;
138
139         if (__fromDatabase)
140         {
141                 SysTryReturn(NID_APP, __pAppInfoHandle, null, E_SYSTEM, "__pAppInfoHandle is null.");
142
143                 result r = E_SUCCESS;
144                 int res = PMINFO_R_OK;
145
146                 pMap = new (std::nothrow) HashMap();
147                 SysTryReturn(NID_APP, pMap, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
148                 pMap->Construct();
149
150                 res = pkgmgrinfo_appinfo_foreach_metadata(__pAppInfoHandle, MetadataHandler, pMap);
151                 if (res != PMINFO_R_OK)
152                 {
153                         SysLog(NID_APP, "pkgmgrinfo_appinfo_foreach_metadata() is failed. result = [%d]", res);
154                         r = E_SYSTEM;
155
156                         pMap->RemoveAll(true);
157                         pMap = null;
158                 }
159
160                 SetLastResult(r);
161         }
162         else
163         {
164                 SysLog(NID_APP, "GetAppMetadataListN() is not available.");
165         }
166
167         return pMap;
168 }
169
170 ArrayList*
171 _PackageAppInfoImpl::GetAppCategoryListN(void) const
172 {
173         ArrayList* pList = null;
174
175         if (__fromDatabase)
176         {
177                 SysTryReturn(NID_APP, __pAppInfoHandle, null, E_SYSTEM, "[E_SYSTEM] __pAppInfoHandle is null.");
178
179                 result r = E_SUCCESS;
180                 int res = PMINFO_R_OK;
181
182                 pList = new (std::nothrow) ArrayList();
183                 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
184                 pList->Construct();
185
186                 res = pkgmgrinfo_appinfo_foreach_category(__pAppInfoHandle, CategoryHandler, pList);
187                 if (res != PMINFO_R_OK)
188                 {
189                         SysLog(NID_APP, "pkgmgrinfo_appinfo_foreach_category() is failed. result = [%d]", res);
190                         r = E_SYSTEM;
191
192                         pList->RemoveAll(true);
193                         pList = null;
194                 }
195
196                 SetLastResult(r);
197
198         }
199         else
200         {
201                 SysLog(NID_APP, "GetAppCategoryListN() is not available.");
202         }
203
204         return pList;
205 }
206
207 bool
208 _PackageAppInfoImpl::IsMenuIconVisible(void) const
209 {
210         return __launchingIconVisible;
211 }
212
213 result
214 _PackageAppInfoImpl::SetMenuIconVisible(bool visible)
215 {
216         __launchingIconVisible = visible;
217         return E_SUCCESS;
218 }
219
220 bool
221 _PackageAppInfoImpl::IsMainApp(void) const
222 {
223         return __mainApp;
224 }
225
226 result
227 _PackageAppInfoImpl::SetMainApp(bool mainApp)
228 {
229         __mainApp = mainApp;
230         return E_SUCCESS;
231 }
232
233 result
234 _PackageAppInfoImpl::AddCategory(String* pCategory)
235 {
236         result r = E_SUCCESS;
237         r = __pAppCategoryList->Add(*pCategory);
238         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pAppCategoryList->Add() is failed.");
239
240         return r;
241 }
242
243 _PackageAppInfoImpl*
244 _PackageAppInfoImpl::GetInstance(PackageAppInfo* pPackageAppInfo)
245 {
246         if (pPackageAppInfo)
247         {
248                 return pPackageAppInfo->__pPackageAppInfoImpl;
249         }
250
251         return null;
252 }
253
254 result
255 _PackageAppInfoImpl::Construct(const AppId& appId)
256 {
257         int res = PMINFO_R_OK;
258         char* pExePath = null;
259         char* pDisplayName = null;
260         char* pMenuIcon = null;
261         char* pSettingIcon = null;
262         char* pNotificationIcon = null;
263         bool mainApp = false;
264         bool menuIconVisible = false;
265
266         std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
267         SysTryReturnResult(NID_APP, pAppId, E_OUT_OF_MEMORY, "pAppId is null");
268
269         res = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &__pAppInfoHandle);
270         SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appinfo failed, res = [%d]", res);
271
272         __fromDatabase = true;
273
274         SetAppId(appId);
275
276         res = pkgmgrinfo_appinfo_get_exec(__pAppInfoHandle, &pExePath);
277         if (res == PMINFO_R_OK)
278         {
279                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_exec(): exe = [%s]", pExePath);
280
281                 String exePath(pExePath);
282                 int startIndex = exePath.GetLength() - 1;
283                 int indexOf = 0;
284                 result r = exePath.LastIndexOf(L'/', startIndex, indexOf);
285                 if (r == E_SUCCESS)
286                 {
287                         String appName;
288                         exePath.SubString(indexOf + 1, appName);
289                         SetAppName(appName);
290                         SysLog(NID_APP, "appName = [%ls]", appName.GetPointer());
291                 }
292                 else
293                 {
294                         SysLog(NID_APP, "LastIndexOf is failed.");
295                 }
296         }
297         else
298         {
299                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_exec() is failed. result = [%d]", res);
300         }
301
302         res = pkgmgrinfo_appinfo_get_label(__pAppInfoHandle, &pDisplayName);
303         if (res == PMINFO_R_OK)
304         {
305                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_label(): displayName = [%s]", pDisplayName);
306                 String displayName(pDisplayName);
307                 SetAppDisplayName(displayName);
308         }
309         else
310         {
311                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_label() is failed. result = [%d]", res);
312         }
313
314         res = pkgmgrinfo_appinfo_get_icon(__pAppInfoHandle, &pMenuIcon);
315         if (res == PMINFO_R_OK)
316         {
317                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_icon(): MenuIcon = [%s]", pMenuIcon);
318                 String menuIcon(pMenuIcon);
319                 SetAppMenuIconPath(menuIcon);
320         }
321         else
322         {
323                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_icon() is failed. result = [%d]", res);
324         }
325
326         res = pkgmgrinfo_appinfo_get_setting_icon(__pAppInfoHandle, &pSettingIcon);
327         if (res == PMINFO_R_OK)
328         {
329                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_setting_icon(): SettingIcon = [%s]", pSettingIcon);
330                 String settingIcon(pSettingIcon);
331                 SetAppSettingIconPath(settingIcon);
332         }
333         else
334         {
335                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_setting_icon() is failed. result = [%d]", res);
336         }
337
338         res = pkgmgrinfo_appinfo_get_notification_icon(__pAppInfoHandle, &pNotificationIcon);
339         if (res == PMINFO_R_OK)
340         {
341                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_notification_icon(): NotificationIcon = [%s]", pNotificationIcon);
342                 String notificationIcon(pNotificationIcon);
343                 SetAppNotificationIconPath(notificationIcon);
344         }
345         else
346         {
347                 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_notification_icon() is failed. result = [%d]", res);
348         }
349
350         res = pkgmgrinfo_appinfo_is_mainapp(__pAppInfoHandle, &mainApp);
351         if (res == PMINFO_R_OK)
352         {
353                 SysLog(NID_APP, "pkgmgrinfo_appinfo_is_mainapp(): mainApp = [%d]", mainApp);
354                 SetMainApp(mainApp);
355         }
356         else
357         {
358                 SysLog(NID_APP, "pkgmgrinfo_appinfo_is_mainapp() is failed. result = [%d]", res);
359         }
360
361         res = pkgmgrinfo_appinfo_is_nodisplay(__pAppInfoHandle, &menuIconVisible);
362         if (res == PMINFO_R_OK)
363         {
364                 SysLog(NID_APP, "pkgmgrinfo_appinfo_is_nodisplay(): menuIconVisible = [%d]", menuIconVisible);
365                 SetMenuIconVisible(!menuIconVisible);
366         }
367         else
368         {
369                 SysLog(NID_APP, "pkgmgrinfo_appinfo_is_nodisplay() is failed. result = [%d]", res);
370         }
371
372         return E_SUCCESS;
373 }
374
375 int
376 _PackageAppInfoImpl::CategoryHandler(const char* pCategoryName, void* pUserData)
377 {
378         SysTryReturn(NID_APP, pCategoryName != null, 0, E_SYSTEM, "[E_SYSTEM] pCategoryName must not be null.");
379
380         SysLog(NID_APP, "Category = [%s]", pCategoryName);
381         ArrayList* pList = (ArrayList*) pUserData;
382
383         String* pCategory = new (std::nothrow) String (pCategoryName);
384         SysTryReturn(NID_APP, pCategory != null, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pCategory instance must not be null.");
385
386         pList->Add(*pCategory);
387
388         return 0;
389 }
390
391 int
392 _PackageAppInfoImpl::MetadataHandler(const char* pKey, const char* pValue, void* pUserData)
393 {
394         SysTryReturn(NID_APP, pKey, 0, E_SYSTEM, "pKey must not be null.");
395         SysTryReturn(NID_APP, pValue, 0, E_SYSTEM, "pValue must not be null.");
396         SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
397
398         SysLog(NID_APP, "Key = [%s], Value = [%s]", pKey, pValue);
399
400         MultiHashMap* pMultiMap = (MultiHashMap*) pUserData;
401         pMultiMap->Add(*(new (std::nothrow) String(pKey)), *(new (std::nothrow) String(pValue)));
402
403         return 0;
404 }
405
406 // to be reviewed
407 _PackageAppInfoImpl::_PackageAppInfoImpl(void)
408         : __launchingIconVisible(true)
409         , __mainApp(false)
410         , __fromDatabase(false)
411         , __pLaunchConditionImplList(null)
412         , __pNotificationImplList(null)
413         , __pAppFeatureImplList(null)
414         , __pDataControlImplList(null)
415         , __pAppControlImplList(null)
416         , __pAppCategoryList(null)
417         , __uniqueId(0)
418         , __pkgId(0)
419         , __appFeature(0)
420         ,__pAppInfoHandle(null)
421 {
422         __pLaunchConditionImplList = new (std::nothrow) ArrayList;
423         SysTryReturnVoidResult(NID_APP, __pLaunchConditionImplList != null, E_OUT_OF_MEMORY, "__pLaunchConditionImplList instance must not be null.");
424         __pLaunchConditionImplList->Construct();
425
426         __pNotificationImplList = new (std::nothrow) ArrayList;
427         SysTryReturnVoidResult(NID_APP, __pNotificationImplList != null, E_OUT_OF_MEMORY, "__pNotificationImplList instance must not be null.");
428         __pNotificationImplList->Construct();
429
430         __pAppFeatureImplList = new (std::nothrow) ArrayList;
431         SysTryReturnVoidResult(NID_APP, __pAppFeatureImplList != null, E_OUT_OF_MEMORY, "__pAppFeatureImplList instance must not be null.");
432         __pAppFeatureImplList->Construct();
433
434         __pDataControlImplList = new (std::nothrow) ArrayList;
435         SysTryReturnVoidResult(NID_APP, __pDataControlImplList != null, E_OUT_OF_MEMORY, "__pDataControlImplList instance must not be null.");
436         __pDataControlImplList->Construct();
437
438         __pAppControlImplList = new (std::nothrow) ArrayList;
439         SysTryReturnVoidResult(NID_APP, __pAppControlImplList != null, E_OUT_OF_MEMORY, "__pAppControlImplList instance must not be null.");
440         __pAppControlImplList->Construct();
441
442         __pAppCategoryList = new (std::nothrow) ArrayList;
443         SysTryReturnVoidResult(NID_APP, __pAppCategoryList != null, E_OUT_OF_MEMORY, "__pAppCategoryList instance must not be null.");
444         __pAppCategoryList->Construct();
445
446         __pNameList = new (std::nothrow) HashMap;
447         SysTryReturnVoidResult(NID_APP, __pNameList != null, E_OUT_OF_MEMORY, "__pNameList instance must not be null.");
448         __pNameList->Construct();
449
450 }
451
452 _PackageAppInfoImpl::~_PackageAppInfoImpl(void)
453 {
454         __pLaunchConditionImplList->RemoveAll(true);
455         delete __pLaunchConditionImplList;
456
457         __pNotificationImplList->RemoveAll(true);
458         delete __pNotificationImplList;
459
460         __pAppFeatureImplList->RemoveAll(true);
461         delete __pAppFeatureImplList;
462
463         __pDataControlImplList->RemoveAll(true);
464         delete __pDataControlImplList;
465
466         __pAppControlImplList->RemoveAll(true);
467         delete __pAppControlImplList;
468
469         __pAppCategoryList->RemoveAll(true);
470         delete __pAppCategoryList;
471
472         __pNameList->RemoveAll(true);
473         delete __pNameList;
474
475         if (__pAppInfoHandle)
476         {
477                 pkgmgrinfo_appinfo_destroy_appinfo(__pAppInfoHandle);
478         }
479 }
480
481 const String&
482 _PackageAppInfoImpl::GetName(void) const
483 {
484         return __name;
485 }
486
487 result
488 _PackageAppInfoImpl::SetName(const String& name)
489 {
490         __name = name;
491         return E_SUCCESS;
492 }
493
494 const String&
495 _PackageAppInfoImpl::GetType(void) const
496 {
497         return __type;
498 }
499
500 result
501 _PackageAppInfoImpl::SetType(const String& type)
502 {
503         __type = type;
504         return E_SUCCESS;
505 }
506
507 const String&
508 _PackageAppInfoImpl::GetDefault(void) const
509 {
510         return __default;
511 }
512
513 result
514 _PackageAppInfoImpl::SetDefault(const String& defaultApp)
515 {
516         __default = defaultApp;
517         return E_SUCCESS;
518 }
519
520 ArrayList*
521 _PackageAppInfoImpl::GetLaunchConditionListN(void) const
522 {
523         result r = E_SUCCESS;
524         Database db;
525         DbStatement* pStmt = null;
526         DbEnumerator* pEnum = null;
527         String query;
528         //int id = 0;
529         ArrayList* pList = null;
530
531         query.Format(1024, L"SELECT * FROM LaunchCondition WHERE ID = %d", GetUniqueId());
532
533         r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
534         SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
535
536         pStmt = db.CreateStatementN(query);
537         SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
538                            GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
539
540         pEnum = db.ExecuteStatementN(*pStmt);
541         if (pEnum != null)
542         {
543                 pList = new (std::nothrow) ArrayList;
544                 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
545                 pList->Construct();
546
547                 while (pEnum->MoveNext() == E_SUCCESS)
548                 {
549                         _LaunchConditionInfoImpl* pLaunchConditionImpl = new (std::nothrow) _LaunchConditionInfoImpl;
550                         SysTryReturn(NID_APP, pLaunchConditionImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
551
552                         String name;
553                         String value;
554
555                         pEnum->GetStringAt(1, name);
556                         pEnum->GetStringAt(2, value);
557
558                         pLaunchConditionImpl->SetName(name);
559                         pLaunchConditionImpl->SetValue(value);
560
561                         pList->Add(*pLaunchConditionImpl);
562                 }
563                 delete pEnum;
564         }
565
566 CATCH:
567         delete pStmt;
568         return pList;
569 }
570
571 ArrayList*
572 _PackageAppInfoImpl::GetLaunchConditionList(void) const
573 {
574         return __pLaunchConditionImplList;
575 }
576
577 result
578 _PackageAppInfoImpl::AddLaunchCondition(const _LaunchConditionInfoImpl& launchConditionImpl)
579 {
580         result r = E_SUCCESS;
581         r = __pLaunchConditionImplList->Add(launchConditionImpl);
582         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pLaunchConditionImplList->Add() is failed.");
583
584         return r;
585 }
586
587 ArrayList*
588 _PackageAppInfoImpl::GetNotificationListN(void) const
589 {
590         result r = E_SUCCESS;
591         Database db;
592         DbStatement* pStmt = null;
593         DbEnumerator* pEnum = null;
594         String query;
595         //int id = 0;
596         ArrayList* pList = null;
597
598         query.Format(1024, L"SELECT * FROM Notification WHERE ID = %d", GetUniqueId());
599
600         r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
601         SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
602
603         pStmt = db.CreateStatementN(query);
604         SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
605                            GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
606
607         pEnum = db.ExecuteStatementN(*pStmt);
608         if (pEnum != null)
609         {
610                 pList = new (std::nothrow) ArrayList;
611                 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
612                 pList->Construct();
613
614                 while (pEnum->MoveNext() == E_SUCCESS)
615                 {
616                         _NotificationInfoImpl* pNotificationImpl = new (std::nothrow) _NotificationInfoImpl;
617                         SysTryReturn(NID_APP, pNotificationImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
618
619                         String name;
620                         String value;
621
622                         pEnum->GetStringAt(1, name);
623                         pEnum->GetStringAt(2, value);
624
625                         pNotificationImpl->SetName(name);
626                         pNotificationImpl->SetValue(value);
627
628                         pList->Add(*pNotificationImpl);
629                 }
630                 delete pEnum;
631         }
632
633 CATCH:
634         delete pStmt;
635         return pList;
636 }
637
638 ArrayList*
639 _PackageAppInfoImpl::GetNotificationList(void) const
640 {
641         return __pNotificationImplList;
642 }
643
644 result
645 _PackageAppInfoImpl::AddNotification(const _NotificationInfoImpl& notificationImpl)
646 {
647         result r = E_SUCCESS;
648         r = __pNotificationImplList->Add(notificationImpl);
649         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pNotificationImplList->Add() is failed.");
650
651         return r;
652 }
653
654 ArrayList*
655 _PackageAppInfoImpl::GetAppFeatureListN(void) const
656 {
657         result r = E_SUCCESS;
658         Database db;
659         DbStatement* pStmt = null;
660         DbEnumerator* pEnum = null;
661         String query;
662         //int id = 0;
663         ArrayList* pList = null;
664
665         query.Format(1024, L"SELECT * FROM AppFeature WHERE ID = %d", GetUniqueId());
666
667         r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
668         SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
669
670         pStmt = db.CreateStatementN(query);
671         SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
672                            GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
673
674         pEnum = db.ExecuteStatementN(*pStmt);
675         if (pEnum != null)
676         {
677                 pList = new (std::nothrow) ArrayList;
678                 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
679                 pList->Construct();
680
681                 while (pEnum->MoveNext() == E_SUCCESS)
682                 {
683                         _AppFeatureInfoImpl* pAppFeatureImpl = new (std::nothrow) _AppFeatureInfoImpl;
684                         SysTryReturn(NID_APP, pAppFeatureImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
685
686                         String name;
687                         String value;
688
689                         pEnum->GetStringAt(1, name);
690                         pEnum->GetStringAt(2, value);
691
692                         pAppFeatureImpl->SetName(name);
693                         pAppFeatureImpl->SetValue(value);
694
695                         pList->Add(*pAppFeatureImpl);
696                 }
697                 delete pEnum;
698         }
699
700 CATCH:
701         delete pStmt;
702         return pList;
703 }
704
705 ArrayList*
706 _PackageAppInfoImpl::GetAppFeatureList(void) const
707 {
708         return __pAppFeatureImplList;
709 }
710
711 HashMapT<String, _AppFeatureInfoImpl*>*
712 _PackageAppInfoImpl::GetAppFeatureMapN(void) const
713 {
714         result r = E_SUCCESS;
715         Database db;
716         DbEnumerator* pEnum = null;
717         String query;
718         //int id = 0;
719         HashMapT<String, _AppFeatureInfoImpl*>* pMap = null;
720
721         query.Format(1024, L"SELECT * FROM AppFeature WHERE ID = %d", GetUniqueId());
722
723         r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
724         SysTryReturn(NID_APP, r == E_SUCCESS, null, r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
725
726         const DbStatement* pStmt = db.CreateStatementN(query);
727         SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
728                            GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
729
730         pEnum = db.ExecuteStatementN(*pStmt);
731         if (pEnum != null)
732         {
733                 pMap = new (std::nothrow) HashMapT<String, _AppFeatureInfoImpl*>;
734                 SysTryReturn(NID_APP, pMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
735                 pMap->Construct();
736
737                 String name;
738                 String value;
739
740                 while (pEnum->MoveNext() == E_SUCCESS)
741                 {
742                         _AppFeatureInfoImpl* pAppFeatureImpl = new (std::nothrow) _AppFeatureInfoImpl;
743                         SysTryReturn(NID_APP, pAppFeatureImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
744
745                         pEnum->GetStringAt(1, name);
746                         pEnum->GetStringAt(2, value);
747
748                         pAppFeatureImpl->SetName(name);
749                         pAppFeatureImpl->SetValue(value);
750
751                         pMap->Add(name, pAppFeatureImpl);
752                 }
753                 delete pEnum;
754         }
755
756 CATCH:
757         delete pStmt;
758         return pMap;
759 }
760
761 result
762 _PackageAppInfoImpl::AddAppFeature(const _AppFeatureInfoImpl& appFeatureImpl)
763 {
764         result r = E_SUCCESS;
765         r = __pAppFeatureImplList->Add(appFeatureImpl);
766         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pAppFeatureImplList->Add() is failed.");
767
768         return r;
769 }
770
771 ArrayList*
772 _PackageAppInfoImpl::GetDataControlListN(void) const
773 {
774         return null;
775 }
776
777 ArrayList*
778 _PackageAppInfoImpl::GetDataControlList(void) const
779 {
780         return __pDataControlImplList;
781 }
782
783 result
784 _PackageAppInfoImpl::AddDataControl(_DataControlInfoImpl* pDataControl)
785 {
786         result r = E_SUCCESS;
787         r = __pDataControlImplList->Add(*pDataControl);
788         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pDataControlImplList->Add() is failed.");
789
790         return r;
791 }
792
793 ArrayList*
794 _PackageAppInfoImpl::GetAppControlListN(void) const
795 {
796         return null;
797 }
798
799 ArrayList*
800 _PackageAppInfoImpl::GetAppControlList(void) const
801 {
802         return __pAppControlImplList;
803 }
804
805 result
806 _PackageAppInfoImpl::AddAppControl(_AppControlInfoImpl* pAppControl)
807 {
808         result r = E_SUCCESS;
809         r = __pAppControlImplList->Add(*pAppControl);
810         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pAppControlImplList->Add() is failed.");
811
812         return r;
813 }
814
815 const String&
816 _PackageAppInfoImpl::GetPackageName(void) const
817 {
818         return __packageName;
819 }
820
821 result
822 _PackageAppInfoImpl::SetPackageName(const String& packageName)
823 {
824         __packageName = packageName;
825         return E_SUCCESS;
826 }
827
828 const String&
829 _PackageAppInfoImpl::GetMainmenuIcon(void) const
830 {
831         return __mainmenuIcon;
832 }
833
834 result
835 _PackageAppInfoImpl::SetMainmenuIcon(const String& mainmenuIcon)
836 {
837         __mainmenuIcon = mainmenuIcon;
838         return E_SUCCESS;
839 }
840
841 const String&
842 _PackageAppInfoImpl::GetSettingIcon(void) const
843 {
844         return __settingIcon;
845 }
846
847 result
848 _PackageAppInfoImpl::SetSettingIcon(const String& setting)
849 {
850         __settingIcon = setting;
851         return E_SUCCESS;
852 }
853
854 const String&
855 _PackageAppInfoImpl::GetQuickpanelIcon(void) const
856 {
857         return __quickpanelIcon;
858 }
859
860 result
861 _PackageAppInfoImpl::SetQuickpanelIcon(const String& quickpanelIcon)
862 {
863         __quickpanelIcon = quickpanelIcon;
864         return E_SUCCESS;
865 }
866
867 bool
868 _PackageAppInfoImpl::IsMainmenuVisible(void) const
869 {
870         return __launchingIconVisible;
871 }
872
873 result
874 _PackageAppInfoImpl::SetMainmenuVisible(bool visible)
875 {
876         __launchingIconVisible = visible;
877         return E_SUCCESS;
878 }
879
880 result
881 _PackageAppInfoImpl::AddName(const String& language, const String& name)
882 {
883         result r = E_SUCCESS;
884         r = __pNameList->Add(language, name);
885
886         return r;
887 }
888
889 HashMap*
890 _PackageAppInfoImpl::GetNameList(void) const
891 {
892         return __pNameList;
893 }
894
895 int
896 _PackageAppInfoImpl::GetUniqueId(void) const
897 {
898         result r = E_SUCCESS;
899         Database db;
900         DbStatement* pStmt = null;
901         DbEnumerator* pEnum = null;
902         String query;
903         int uniqueId = 0;
904
905         query.Format(1024, L"SELECT UNIQUE_ID FROM AppInfo WHERE APP_NAME = '%ls' and ID = %d", __name.GetPointer(), __pkgId);
906
907         r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
908         SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
909
910         pStmt = db.CreateStatementN(query);
911         SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
912                            GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
913
914         pEnum = db.ExecuteStatementN(*pStmt);
915         if (pEnum != null)
916         {
917                 if (pEnum->MoveNext() == E_SUCCESS)
918                 {
919                         pEnum->GetIntAt(0, uniqueId);
920                 }
921
922                 delete pEnum;
923         }
924         else
925         {
926                 r = E_OBJ_NOT_FOUND;
927         }
928
929 CATCH:
930         delete pStmt;
931         return uniqueId;
932 }
933
934 int
935 _PackageAppInfoImpl::GetPkgId(void) const
936 {
937         return __pkgId;
938 }
939
940 result
941 _PackageAppInfoImpl::SetUniqueId(int id)
942 {
943         __uniqueId = id;
944         return E_SUCCESS;
945 }
946
947 result
948 _PackageAppInfoImpl::SetPkgId(int id)
949 {
950         __pkgId = id;
951         return E_SUCCESS;
952 }
953
954 int
955 _PackageAppInfoImpl::GetAppFeature(void) const
956 {
957         return __appFeature;
958 }
959
960 result
961 _PackageAppInfoImpl::SetAppFeature(int feature)
962 {
963         __appFeature = feature;
964         return E_SUCCESS;
965 }
966
967 _LaunchConditionInfoImpl::_LaunchConditionInfoImpl(void)
968 {
969
970 }
971
972 _LaunchConditionInfoImpl::~_LaunchConditionInfoImpl(void)
973 {
974
975 }
976
977 const String&
978 _LaunchConditionInfoImpl::GetName(void) const
979 {
980         return __name;
981 }
982
983 result
984 _LaunchConditionInfoImpl::SetName(const String& name)
985 {
986         __name = name;
987         return E_SUCCESS;
988 }
989
990 const String&
991 _LaunchConditionInfoImpl::GetValue(void) const
992 {
993         return __value;
994 }
995
996 result
997 _LaunchConditionInfoImpl::SetValue(const String& value)
998 {
999         __value = value;
1000         return E_SUCCESS;
1001 }
1002
1003 _NotificationInfoImpl::_NotificationInfoImpl(void)
1004 {
1005
1006 }
1007
1008 _NotificationInfoImpl::~_NotificationInfoImpl(void)
1009 {
1010
1011 }
1012
1013 const String&
1014 _NotificationInfoImpl::GetName(void) const
1015 {
1016         return __name;
1017 }
1018
1019 result
1020 _NotificationInfoImpl::SetName(const String& name)
1021 {
1022         __name = name;
1023         return E_SUCCESS;
1024 }
1025
1026 const String&
1027 _NotificationInfoImpl::GetValue(void) const
1028 {
1029         return __value;
1030 }
1031
1032 result
1033 _NotificationInfoImpl::SetValue(const String& value)
1034 {
1035         __value = value;
1036         return E_SUCCESS;
1037 }
1038
1039 _AppFeatureInfoImpl::_AppFeatureInfoImpl(void)
1040 {
1041
1042 }
1043
1044 _AppFeatureInfoImpl::~_AppFeatureInfoImpl(void)
1045 {
1046
1047 }
1048
1049 const String&
1050 _AppFeatureInfoImpl::GetName(void) const
1051 {
1052         return __name;
1053 }
1054
1055 result
1056 _AppFeatureInfoImpl::SetName(const String& name)
1057 {
1058         __name = name;
1059         return E_SUCCESS;
1060 }
1061
1062 const String&
1063 _AppFeatureInfoImpl::GetValue(void) const
1064 {
1065         return __value;
1066 }
1067
1068 result
1069 _AppFeatureInfoImpl::SetValue(const String& value)
1070 {
1071         __value = value;
1072         return E_SUCCESS;
1073 }
1074
1075 _DataControlTypeImpl::_DataControlTypeImpl(void)
1076 {
1077
1078 }
1079
1080 _DataControlTypeImpl::~_DataControlTypeImpl(void)
1081 {
1082
1083 }
1084
1085 const String&
1086 _DataControlTypeImpl::GetType(void) const
1087 {
1088         return __type;
1089 }
1090
1091 result
1092 _DataControlTypeImpl::SetType(const String& type)
1093 {
1094         __type = type;
1095         return E_SUCCESS;
1096 }
1097
1098 const String&
1099 _DataControlTypeImpl::GetAccess(void) const
1100 {
1101         return __access;
1102 }
1103
1104 result
1105 _DataControlTypeImpl::SetAccess(const String& access)
1106 {
1107         __access = access;
1108         return E_SUCCESS;
1109 }
1110
1111 _DataControlInfoImpl::_DataControlInfoImpl(void)
1112         : __pControlTypeList(null)
1113 {
1114         __pControlTypeList = new (std::nothrow) ArrayList;
1115         SysTryReturnVoidResult(NID_APP, __pControlTypeList != null, E_OUT_OF_MEMORY, "__pControlTypeList instance must not be null.");
1116         __pControlTypeList->Construct();
1117 }
1118
1119 _DataControlInfoImpl::~_DataControlInfoImpl(void)
1120 {
1121         __pControlTypeList->RemoveAll(true);
1122         delete __pControlTypeList;
1123 }
1124
1125 const String&
1126 _DataControlInfoImpl::GetProviderId(void) const
1127 {
1128         return __providerId;
1129 }
1130
1131 result
1132 _DataControlInfoImpl::SetProviderId(const String& providerId)
1133 {
1134         __providerId = providerId;
1135         return E_SUCCESS;
1136 }
1137
1138 ArrayList*
1139 _DataControlInfoImpl::GetControlTypeList(void) const
1140 {
1141         return __pControlTypeList;
1142 }
1143
1144 result
1145 _DataControlInfoImpl::AddControlType(_DataControlTypeImpl* pControlType)
1146 {
1147         __pControlTypeList->Add(*pControlType);
1148         return E_SUCCESS;
1149 }
1150
1151 _AppControlResolutionInfoImpl::_AppControlResolutionInfoImpl(void)
1152         : __pUriScheme(null)
1153         , __pMimeType(null)
1154 {
1155
1156 }
1157
1158 _AppControlResolutionInfoImpl::~_AppControlResolutionInfoImpl(void)
1159 {
1160                 delete __pUriScheme;
1161                 delete __pMimeType;
1162 }
1163
1164 String*
1165 _AppControlResolutionInfoImpl::GetUriScheme(void) const
1166 {
1167         return __pUriScheme;
1168 }
1169
1170 result
1171 _AppControlResolutionInfoImpl::SetUriScheme(String* pUriScheme)
1172 {
1173         __pUriScheme = pUriScheme;
1174         return E_SUCCESS;
1175 }
1176
1177 String*
1178 _AppControlResolutionInfoImpl::GetMimeType(void) const
1179 {
1180         return __pMimeType;
1181 }
1182
1183 result
1184 _AppControlResolutionInfoImpl::SetMimeType(String* pMimeType)
1185 {
1186         __pMimeType = pMimeType;
1187         return E_SUCCESS;
1188 }
1189
1190 _AppControlCapabilityInfoImpl::_AppControlCapabilityInfoImpl(void)
1191         : __uniqueId(0)
1192         ,__appControlId(0)
1193         ,__pResolutionList(null)
1194 {
1195         __pResolutionList = new (std::nothrow) ArrayList;
1196         SysTryReturnVoidResult(NID_APP, __pResolutionList != null, E_OUT_OF_MEMORY, "__pResolutionList instance must not be null.");
1197         __pResolutionList->Construct();
1198 }
1199
1200 _AppControlCapabilityInfoImpl::~_AppControlCapabilityInfoImpl(void)
1201 {
1202         __pResolutionList->RemoveAll(true);
1203         delete __pResolutionList;
1204 }
1205
1206 int
1207 _AppControlCapabilityInfoImpl::GetUniqueId(void) const
1208 {
1209         return __uniqueId;
1210 }
1211
1212 result
1213 _AppControlCapabilityInfoImpl::SetUniqueId(int uniqueId)
1214 {
1215         __uniqueId = uniqueId;
1216         return E_SUCCESS;
1217 }
1218
1219 int
1220 _AppControlCapabilityInfoImpl::GetAppControlId(void) const
1221 {
1222         return __appControlId;
1223 }
1224
1225 result
1226 _AppControlCapabilityInfoImpl::SetAppControlId(int appControlId)
1227 {
1228         __appControlId = appControlId;
1229         return E_SUCCESS;
1230 }
1231
1232 const String&
1233 _AppControlCapabilityInfoImpl::GetOperationId(void) const
1234 {
1235         return __operationId;
1236 }
1237
1238 result
1239 _AppControlCapabilityInfoImpl::SetOperationId(const String& operationId)
1240 {
1241         __operationId = operationId;
1242         return E_SUCCESS;
1243 }
1244
1245 ArrayList*
1246 _AppControlCapabilityInfoImpl::GetResolutionList(void) const
1247 {
1248         return __pResolutionList;
1249 }
1250
1251 result
1252 _AppControlCapabilityInfoImpl::AddResolution(_AppControlResolutionInfoImpl* pResolutionImpl)
1253 {
1254         result r = E_SUCCESS;
1255         r = __pResolutionList->Add(*pResolutionImpl);
1256         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pResolutionList->Add() is failed.");
1257
1258         return r;
1259 }
1260
1261 _AppControlInfoImpl::_AppControlInfoImpl(void)
1262         : __uniqueId(0)
1263         ,__pCapabilityList(null)
1264 {
1265         __pCapabilityList = new (std::nothrow) ArrayList;
1266         SysTryReturnVoidResult(NID_APP, __pCapabilityList != null, E_OUT_OF_MEMORY, "__pCapabilityList instance must not be null.");
1267         __pCapabilityList->Construct();
1268 }
1269
1270 _AppControlInfoImpl::~_AppControlInfoImpl(void)
1271 {
1272         __pCapabilityList->RemoveAll(true);
1273         delete __pCapabilityList;
1274 }
1275
1276 int
1277 _AppControlInfoImpl::GetUniqueId(void) const
1278 {
1279         return __uniqueId;
1280 }
1281
1282 result
1283 _AppControlInfoImpl::SetUniqueId(int uniqueId)
1284 {
1285         __uniqueId = uniqueId;
1286         return E_SUCCESS;
1287 }
1288
1289 const String&
1290 _AppControlInfoImpl::GetProviderId(void) const
1291 {
1292         return __providerId;
1293 }
1294
1295 result
1296 _AppControlInfoImpl::SetProviderId(const String& providerId)
1297 {
1298         __providerId = providerId;
1299         return E_SUCCESS;
1300 }
1301
1302 const String&
1303 _AppControlInfoImpl::GetCategory(void) const
1304 {
1305         return __category;
1306 }
1307
1308 result
1309 _AppControlInfoImpl::SetCategory(const String& category)
1310 {
1311         __category = category;
1312         return E_SUCCESS;
1313 }
1314
1315 ArrayList*
1316 _AppControlInfoImpl::GetCapabilityList(void) const
1317 {
1318         return __pCapabilityList;
1319 }
1320
1321 result
1322 _AppControlInfoImpl::AddCapability(_AppControlCapabilityInfoImpl* pCapability)
1323 {
1324         result r = E_SUCCESS;
1325         r = __pCapabilityList->Add(*pCapability);
1326         SysTryReturnResult(NID_APP, !IsFailed(r), r, "__pCapabilityList->Add() is failed.");
1327
1328         return r;
1329 }
1330
1331 } } } // Tizen::App::Package