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