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