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