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