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