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