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