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