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