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