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