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