2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FAppPkg_PackageManagerImpl.cpp
19 * @brief This is the implementation for the _PackageManagerImpl class.
27 #include <unique_ptr.h>
29 #include <package-manager-types.h>
31 #include <FAppPkgPackageManager.h>
32 #include <FAppPkgPackageAppInfo.h>
33 #include <FAppPkgPackageInfo.h>
34 #include <FAppPkgIPackageInstallationEventListener.h>
35 #include <FAppPkgIPackageInstallationResponseListener.h>
36 #include <FAppPkgIPackageUninstallationResponseListener.h>
37 #include <FBaseSysLog.h>
39 #include <FIoRegistry.h>
40 #include <FSysSystemTime.h>
41 #include <FBase_StringConverter.h>
43 #include "FAppPkg_PackageManagerImpl.h"
44 #include "FAppPkg_PackageInfoImpl.h"
45 #include "FAppPkg_PackageAppInfoImpl.h"
46 #include "FAppPkg_PackageParser.h"
47 #include "FApp_AppInfo.h"
48 #include "FApp_PackageManagerProxy.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Runtime;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Io;
54 using namespace Tizen::System;
56 namespace Tizen { namespace App { namespace Package
59 PackageManager* pPackageManagerInstance = null;
61 Tizen::Base::Collection::HashMap _PackageManagerImpl::__installationList;
64 _PackageManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
66 IPackageInstallationEventListener* pListener = dynamic_cast<IPackageInstallationEventListener*> (&listener);
67 SysTryReturnVoidResult(NID_APP, pListener != null, E_OUT_OF_MEMORY, "pListener instance must not be null.");
69 const _PackageManagerEventArg* pArg = dynamic_cast<const _PackageManagerEventArg*>(&arg);
70 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "pArg instance must not be null.");
72 if (pArg->__eventKey == L"end")
74 if (pArg->__eventValue == L"ok")
78 SysLog(NID_APP, "Installation is Completed. [PackageId = %ls]", pArg->__packageId.GetPointer());
79 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
83 SysLog(NID_APP, "Uninstallation is Completed. [PackageId = %ls]", pArg->__packageId.GetPointer());
84 pListener->OnPackageUninstallationCompleted(pArg->__packageId, true);
91 SysLog(NID_APP, "Installation is Completed(Error). [PackageId = %ls]", pArg->__packageId.GetPointer());
92 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
96 SysLog(NID_APP, "Uninstallation is Completed(Error). [PackageId = %ls]", pArg->__packageId.GetPointer());
97 pListener->OnPackageUninstallationCompleted(pArg->__packageId, false);
101 else if (pArg->__eventKey == L"install_percent")
103 std::unique_ptr<char[]> pProgress(_StringConverter::CopyToCharArrayN(pArg->__eventValue));
106 sscanf(pProgress.get(), "%d", &progress);
108 SysLog(NID_APP, "InstallationInProgress [%d]", progress);
109 pListener->OnPackageInstallationInProgress(pArg->__packageId, progress);
114 _PackageManagerImpl::GetPackageIdByAppId(const AppId& appId)
116 SysTryReturn(NID_APP, appId.IsEmpty() == false, L"", E_INVALID_ARG, "appId is empty");
120 if (appId.StartsWith(L".", 10) == true)
122 appId.SubString(0, 10, packageId);
127 char* pPackageId = null;
128 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
130 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
131 SysTryReturn(NID_APP, pAppId, L"", E_OUT_OF_MEMORY, "pAppId is null");
133 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
134 SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], appId=[%s]", result, pAppId.get());
136 result = pkgmgrinfo_appinfo_get_pkgname(pAppInfoHandle, &pPackageId);
138 packageId.Append(pPackageId);
142 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
146 SysLog(NID_APP, "appId = [%ls], packageId = [%ls]", appId.GetPointer(), packageId.GetPointer());
152 _PackageManagerImpl::AddEventListener(IPackageInstallationEventListener* pListener, int priority)
154 SysTryReturnResult(NID_APP, (priority < 3) && (priority >= 0), E_INVALID_ARG, "priority is invalid.");
156 result r = E_SUCCESS;
159 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
160 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
162 while (pEnum->MoveNext() == E_SUCCESS)
164 _PackageManagerEvent* pEvent = null;
165 pEnum->GetCurrent(pEvent);
168 if (pEvent->__pListener == pListener)
170 SysLog(NID_APP, "The event listener already exist. listener = [0x%x]", pListener);
171 return E_OBJ_ALREADY_EXIST;
176 if (__pListeningClient == null)
178 __pListeningClient = pkgmgr_client_new(PC_LISTENING);
179 SysTryReturnResult(NID_APP, __pListeningClient != null, E_SYSTEM, "pkgmgr_client_new(PC_LISTENING) failed");
181 res = pkgmgr_client_listen_status(__pListeningClient, PackageEventHandler, this);
182 if (res < PKGMGR_R_OK)
184 pkgmgr_client_free(__pListeningClient);
185 __pListeningClient = null;
187 if (res == PKGMGR_R_EINVAL)
189 SysLog(NID_APP, "pkgmgr_client_listen_status() returns ARGV error");
190 return E_INVALID_ARG;
192 else if (res == PKGMGR_R_ECOMM)
194 SysLog(NID_APP, "pkgmgr_client_listen_status() returns COMM error");
196 else if (res == PKGMGR_R_ETIMEOUT)
198 SysLog(NID_APP, "pkgmgr_client_listen_status() returns TIME_OUT error");
200 else if (res == PKGMGR_R_ERROR)
202 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error");
206 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error, res = %d", res);
213 _PackageManagerEvent* pEvent = new (std::nothrow) _PackageManagerEvent();
214 SysTryReturnResult(NID_APP, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
216 r = pEvent->Construct();
217 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "pEvent->Construct() failed.");
219 pEvent->__pListener = pListener;
221 r = pEvent->AddListener(*pListener, true);
222 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "pEvent->AddListener() failed. [%s]", GetErrorMessage(r));
224 r = __packageEventListenerList.Add(pEvent);
225 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
227 SysLog(NID_APP, "Add PackageInstallationEventListener = [0x%x]", pListener);
232 _PackageManagerImpl::RemoveEventListener(IPackageInstallationEventListener* pListener)
234 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
235 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
237 result r = E_SUCCESS;
239 while (pEnum->MoveNext() == E_SUCCESS)
241 _PackageManagerEvent* pEvent = null;
242 pEnum->GetCurrent(pEvent);
245 if (pEvent->__pListener == pListener)
247 r = __packageEventListenerList.Remove(pEvent);
248 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
252 SysLog(NID_APP, "Remove PackageInstallationEventListener = [0x%x]", pListener);
258 return E_OBJ_NOT_FOUND;
262 _PackageManagerImpl::GetPackageInfoN(const PackageId& packageId) const
264 SysTryReturn(NID_APP, packageId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageId is empty.");
265 SysTryReturn(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, null, E_INVALID_ARG, "packageId is invalid.(length)");
267 result r = E_SUCCESS;
268 PackageInfo* pPackageInfo = null;
270 pPackageInfo = new (std::nothrow) PackageInfo;
271 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
273 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
274 r = pPackageInfoImpl->Construct(packageId);
275 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] packageId (%ls) is not found.", packageId.GetPointer());
285 _PackageManagerImpl::GetPackageAppInfoN(const AppId& appId) const
287 SysTryReturn(NID_APP, appId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
289 result r = E_SUCCESS;
290 PackageAppInfo* pPackageAppInfo = null;
292 pPackageAppInfo = new (std::nothrow) PackageAppInfo;
293 SysTryReturn(NID_APP, pPackageAppInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageAppInfo instance must not be null.");
295 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo);
296 r = pPackageAppInfoImpl->Construct(appId);
297 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] appId (%ls) is not found.", appId.GetPointer());
299 return pPackageAppInfo;
302 delete pPackageAppInfo;
307 _PackageManagerImpl::GetPackageInfoListN(void) const
309 result r = E_SUCCESS;
311 ArrayList* pList = null;
313 pList = new (std::nothrow) ArrayList();
314 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
317 res = pkgmgrinfo_pkginfo_get_list(PackageInfoEventHandler, pList);
320 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_list() is failed. result = [%d]", res);
322 pList->RemoveAll(true);
331 _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
333 SysTryReturn(NID_APP, packageId.IsEmpty() == false, false, E_INVALID_ARG, "packageId is empty");
336 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
338 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
339 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
341 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
344 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", result, pPackageId.get());
348 if(pPackageInfoHandle)
350 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
353 SysLog(NID_APP, "packageId = [%ls] is installed.", packageId.GetPointer());
359 _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& packagePath, IPackageInstallationResponseListener* pListener)
361 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
362 SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
363 SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
365 String extension = File::GetFileExtension(packagePath);
366 SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
368 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(packagePath));
369 SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null");
371 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
372 SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null");
374 if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
376 SysLog(NID_APP, "packageId = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
380 SysLog(NID_APP, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
384 result r = E_SUCCESS;
385 _PackageManagerProxy packageManagerProxy;
386 r = packageManagerProxy.Construct();
387 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
389 r = packageManagerProxy.InstallPackage(packageId, packagePath, null);
390 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.InstallPackage() failed.");
392 if (__pRequestClient == null)
394 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
395 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
398 int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), null, PM_QUIET, InstallationEventHandler, pListener);
400 if (res < PKGMGR_R_OK)
402 pkgmgr_client_free(__pRequestClient);
403 __pRequestClient = null;
405 if (res == PKGMGR_R_EINVAL)
407 SysLog(NID_APP, "pkgmgr_client_install() returns ARGV error");
408 return E_INVALID_ARG;
410 else if (res == PKGMGR_R_ECOMM)
412 SysLog(NID_APP, "pkgmgr_client_install() returns COMM error");
414 else if (res == PKGMGR_R_ETIMEOUT)
416 SysLog(NID_APP, "pkgmgr_client_install() returns TIME_OUT error");
418 else if (res == PKGMGR_R_ERROR)
420 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error");
424 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error, res = %d", res);
434 _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener)
436 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
437 SysTryReturnResult(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The packageId is invalid.(length)");
438 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
440 result r = E_SUCCESS;
443 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
445 _PackageManagerProxy packageManagerProxy;
446 r = packageManagerProxy.Construct();
447 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
449 r = packageManagerProxy.UninstallPackage(packageId, pListener);
450 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.UninstallPackage() failed.");
452 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
453 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
455 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
456 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
458 res = pkgmgrinfo_pkginfo_get_type(pPackageInfoHandle, &pType);
459 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
461 if (__pRequestClient == null)
463 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
464 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
467 res = pkgmgr_client_uninstall(__pRequestClient, pType, pPackageId.get(), PM_QUIET, UninstallationEventHandler, pListener);
468 SysLog(NID_APP, "pkgmgr_client_uninstall - req_id=[%d], packageId=[%s], type=[%s]", res, pPackageId.get(), pType);
470 if(pPackageInfoHandle)
472 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
475 if (res < PKGMGR_R_OK)
477 pkgmgr_client_free(__pRequestClient);
478 __pRequestClient = null;
480 if (res == PKGMGR_R_EINVAL)
482 SysLog(NID_APP, "pkgmgr_client_uninstall() returns ARGV error");
483 return E_INVALID_ARG;
485 else if (res == PKGMGR_R_ECOMM)
487 SysLog(NID_APP, "pkgmgr_client_uninstall() returns COMM error");
489 else if (res == PKGMGR_R_ETIMEOUT)
491 SysLog(NID_APP, "pkgmgr_client_uninstall() returns TIME_OUT error");
493 else if (res == PKGMGR_R_ERROR)
495 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error");
499 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error, res = %d", res);
509 _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId)
511 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
512 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
516 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
517 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
519 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
520 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
522 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
523 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
525 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
526 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
528 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
529 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
531 if (storage == PMINFO_EXTERNAL_STORAGE)
533 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
534 return E_INVALID_OPERATION;
537 if (__pRequestClient == null)
539 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
540 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
543 res = pkgmgr_client_move(__pRequestClient, pType, pPackageId.get(), PM_MOVE_TO_SDCARD, PM_QUIET);
545 if(packageInfoHandle)
547 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
550 if (res < PKGMGR_R_OK)
552 pkgmgr_client_free(__pRequestClient);
553 __pRequestClient = null;
555 if (res == PKGMGR_R_EINVAL)
557 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
558 return E_INVALID_ARG;
560 else if (res == PKGMGR_R_ERROR)
562 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
566 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
576 _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
578 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
579 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
583 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
584 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
586 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
587 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
589 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
590 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
592 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
593 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
595 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
596 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
598 if (storage == PMINFO_INTERNAL_STORAGE)
600 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
601 return E_INVALID_OPERATION;
604 if (__pRequestClient == null)
606 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
607 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
610 res = pkgmgr_client_move(__pRequestClient, pType, pPackageId.get(), PM_MOVE_TO_INTERNAL, PM_QUIET);
612 if(packageInfoHandle)
614 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
617 if (res < PKGMGR_R_OK)
619 pkgmgr_client_free(__pRequestClient);
620 __pRequestClient = null;
622 if (res == PKGMGR_R_EINVAL)
624 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
625 return E_INVALID_ARG;
627 else if (res == PKGMGR_R_ERROR)
629 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
633 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
643 _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
645 SysLog(NID_APP, "reqId[%d], Type[%s], PackageId[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
649 IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData;
651 if (strcmp(pKey, "end") == 0)
653 if (strcmp(pVal, "ok") == 0)
655 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
656 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_SUCCESS)");
660 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
661 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE)");
666 else if (strcmp(pKey, "install_percent") == 0)
669 sscanf(pVal, "%d", &progress);
671 pListener->OnPackageInstallationInProgressResponseReceived(pPackageId, progress);
672 SysLog(NID_APP, "OnPackageInstallationInProgressResponseReceived(%s, %d)", pPackageId, progress);
680 _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
682 SysLog(NID_APP, "reqId[%d], Type[%s], PackageId[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
686 if (strcmp(pKey, "end") == 0)
688 IPackageUninstallationResponseListener* pListener = (IPackageUninstallationResponseListener*) pData;
690 if (strcmp(pVal, "ok") == 0)
692 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(true)");
693 pListener->OnPackageUninstallationResponseReceived(pPackageId, true);
697 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(false)");
698 pListener->OnPackageUninstallationResponseReceived(pPackageId, false);
709 _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
711 SysTryReturn(NID_APP, filePath.IsEmpty() == false, null, E_INVALID_ARG, "filePath is empty.");
712 SysTryReturn(NID_APP, File::IsFileExist(filePath) == true, null, E_FILE_NOT_FOUND, "package is not existed.");
714 String extension = File::GetFileExtension(filePath);
715 SysTryReturn(NID_APP, extension.IsEmpty() == false, null, E_INVALID_ARG, "extension is empty.");
717 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(filePath));
718 SysTryReturn(NID_APP, pPackagePath, null, E_OUT_OF_MEMORY, "pPackagePath is null.");
720 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
721 SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null.");
723 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
724 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
726 SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
730 if (strcasecmp(pExtension.get(), "tpk") == 0)
732 _PackageParser packageParser;
734 res = packageParser.Construct(pPackageInfo.get());
735 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
737 res = packageParser.Parse(filePath);
738 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
740 else if (strcasecmp(pExtension.get(), "wgt") == 0)
742 pkgmgr_info* pPkgmgrInfo = null;
744 pPkgmgrInfo = pkgmgr_client_check_pkginfo_from_file(pPackagePath.get());
745 SysTryReturn(NID_APP, pPkgmgrInfo, null, E_PARSING_FAILED, "pkgmgr_client_check_pkginfo_from_file(%s) is failed.", pPackagePath.get());
747 _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo;
748 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
750 SysLog(NID_APP, "id(%s), version(%s), label(%s), description(%s), author(%s), icon_size(%d), pkgname(%s)", pPkgInfo->pkgid, pPkgInfo->version, pPkgInfo->label,
751 pPkgInfo->pkg_description, pPkgInfo->author, pPkgInfo->icon_size, pPkgInfo->pkg_name);
753 pPackageInfoImpl->SetType(PACKAGE_TYPE_WGT);
754 pPackageInfoImpl->SetId(pPkgInfo->pkgid);
755 pPackageInfoImpl->SetVersion(pPkgInfo->version);
756 pPackageInfoImpl->SetDisplayName(pPkgInfo->label);
757 pPackageInfoImpl->SetDescription(pPkgInfo->pkg_description);
758 pPackageInfoImpl->SetAuthor(pPkgInfo->author);
759 pPackageInfoImpl->SetMainAppId(pPkgInfo->pkg_name);
761 if (pPkgInfo->privilege_list)
764 pList = g_list_first(pPkgInfo->privilege_list);
767 char* pPrivilege = (char*)pList->data;
770 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege));
773 pList = g_list_next(pList);
775 g_list_free(pPkgInfo->privilege_list);
778 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
779 SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
781 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
783 pPackageAppInfoImpl->SetAppId(pPkgInfo->pkg_name);
784 pPackageAppInfoImpl->SetAppName(pPkgInfo->label);
785 pPackageAppInfoImpl->SetAppDisplayName(pPkgInfo->label);
786 pPackageAppInfoImpl->SetMainApp(true);
787 if ((pPkgInfo->icon_buf) && (pPkgInfo->icon_size > 0))
789 String iconPath("/tmp/icon.png");
791 file.Construct(iconPath, "w+");
792 file.Write(pPkgInfo->icon_buf, pPkgInfo->icon_size);
794 pPackageAppInfoImpl->SetAppTempIconPath(iconPath);
797 pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release());
799 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
803 SysTryReturn(NID_APP, false, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
806 return pPackageInfo.release();
810 _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
812 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
814 std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
815 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
817 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
818 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
822 int res = PMINFO_R_OK;
823 pkgmgrinfo_pkginfo_filter_h handle = null;
825 res = pkgmgrinfo_pkginfo_filter_create(&handle);
826 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
828 while(pEnum->MoveNext() == E_SUCCESS)
830 String* pKey = static_cast< String* >(pEnum->GetKey());
831 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
833 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
834 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
836 bool value = pVal->ToBool();
838 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
840 if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
842 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
843 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
845 else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
847 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
848 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
850 else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
852 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
853 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
855 else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
857 String installedStorage;
860 installedStorage = L"installed_external";
864 installedStorage = L"installed_internal";
867 std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
868 SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
870 SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
872 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
873 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
877 SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
881 res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList.get());
882 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed. [%d]", res);
887 pkgmgrinfo_pkginfo_filter_destroy(handle);
890 if (pList->GetCount() <= 0)
892 AppLog("pList's count is 0.");
896 return pList.release();
900 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) const
902 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
904 std::unique_ptr< IMapEnumerator > pEnum(packageAppFilterMap.GetMapEnumeratorN());
905 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
907 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
908 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
913 bool definedKey = false;
914 bool metadataKey = false;
916 ArrayList metadataList;
918 pkgmgrinfo_appinfo_filter_h handle = null;
919 pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null;
921 res = pkgmgrinfo_appinfo_filter_create(&handle);
922 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res);
924 res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle);
925 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res);
927 while(pEnum->MoveNext() == E_SUCCESS)
929 String* pKey = static_cast< String* >(pEnum->GetKey());
930 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
932 if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE)
936 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
937 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
939 bool nodisplay = !(pVal->ToBool());
940 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), nodisplay);
942 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, nodisplay);
943 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(NODISPLAY, %d) is failed. [%d]", nodisplay, res);
945 else if ((*pKey) == PACKAGE_APP_FILTER_CATEGORY)
949 String* pVal = static_cast< String* >(pEnum->GetValue());
950 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
952 SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
954 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
955 SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
957 res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pValue.get());
958 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pValue.get(), res);
964 String* pVal = static_cast< String* >(pEnum->GetValue());
965 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
967 SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
969 std::unique_ptr<char[]> pMetaKey(_StringConverter::CopyToCharArrayN(*pKey));
970 SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null.");
972 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
973 SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
975 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), pValue.get());
976 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, %s) is failed. [%d]", pMetaKey.get(), pValue.get(), res);
980 if ((definedKey == true) && (metadataKey == false))
982 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList.get());
983 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_foreach_appinfo() failed. [%d]", res);
985 else if ((definedKey == false) && (metadataKey == true))
987 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList.get());
988 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_foreach() failed. [%d]", res);
994 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list);
995 if (res != PMINFO_R_OK)
997 SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res);
1001 metadataList.Construct();
1003 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, &metadataList);
1004 if (res != PMINFO_R_OK)
1006 SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res);
1010 for (int i = 0; i < list.GetCount(); i++)
1012 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i));
1013 if (pPackageAppInfo)
1015 AppLog("PackageAppFilter - AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1017 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1018 appIdList.Add(pAppId.release());
1022 for (int j = 0; j < metadataList.GetCount(); j++)
1024 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j));
1025 if (pPackageAppInfo)
1027 AppId appId = pPackageAppInfo->GetAppId();
1029 if (appIdList.Contains(appId) == true)
1031 AppLog("AppId [%ls] is matched.", appId.GetPointer());
1033 std::unique_ptr< PackageAppInfo > pAppInfo(new (std::nothrow) PackageAppInfo);
1034 SysTryCatch(NID_APP, pAppInfo, , E_OUT_OF_MEMORY, "pAppInfo is null.");
1036 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
1037 pPackageAppInfoImpl->Construct(appId);
1039 pList->Add(pAppInfo.release());
1043 AppLog("AppId [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1052 pkgmgrinfo_appinfo_filter_destroy(handle);
1057 pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle);
1060 if (pList->GetCount() <= 0)
1062 AppLog("pList's count is 0.");
1066 return pList.release();
1070 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
1072 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap Count is invalid.");
1073 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap Count is invalid.");
1075 ArrayList appIdList;
1077 std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap));
1078 if (pPackageFilterList == null)
1080 SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null.");
1084 for (int i = 0; i < pPackageFilterList->GetCount(); i++)
1086 PackageInfo* pPackageInfo = dynamic_cast < PackageInfo* >(pPackageFilterList->GetAt(i));
1089 std::unique_ptr< IList > pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
1090 if (pPackageAppInfoList)
1092 for (int j = 0; j < pPackageAppInfoList->GetCount(); j++)
1094 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppInfoList->GetAt(j));
1095 if (pPackageAppInfo)
1097 AppLog("PackageFilter - AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1099 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1100 appIdList.Add(pAppId.release());
1107 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList);
1108 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
1110 std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap));
1111 if (pAppFilterList == null)
1113 SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null.");
1117 for (int k = 0; k < pAppFilterList->GetCount(); k++)
1119 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k));
1120 if (pPackageAppInfo)
1122 AppId appId = pPackageAppInfo->GetAppId();
1123 AppLog("AppFilter - AppId [%ls]", appId.GetPointer());
1125 if (appIdList.Contains(appId) == true)
1127 AppLog("AppId [%ls] is matched.", appId.GetPointer());
1129 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1130 SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null.");
1132 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1133 pPackageAppInfoImpl->Construct(appId);
1135 pList->Add(pPackageAppInfo.release());
1139 AppLog("AppId [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1144 if (pList->GetCount() <= 0)
1146 AppLog("pList's count is 0.");
1150 return pList.release();
1154 _PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1156 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1157 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1159 result r = E_SUCCESS;
1160 int res = PMINFO_R_OK;
1161 char* pPackageId = null;
1162 ArrayList* pList = (ArrayList*)pUserData;
1164 res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
1165 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
1167 std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
1168 SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1170 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1171 r = pPackageInfoImpl->Construct(pPackageId);
1172 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
1174 pList->Add(*pPackageInfo.release());
1180 _PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1182 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1183 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1185 result r = E_SUCCESS;
1186 int res = PMINFO_R_OK;
1187 char* pAppId = null;
1188 ArrayList* pList = (ArrayList*)pUserData;
1190 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1191 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1193 SysLog(NID_APP, "appId = [%s]", pAppId);
1195 std::unique_ptr<PackageAppInfo> pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1196 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1198 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1199 r = pPackageAppInfoImpl->Construct(pAppId);
1200 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1202 pList->Add(*pPackageAppInfo.release());
1208 _PackageManagerImpl::PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1210 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1211 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1213 result r = E_SUCCESS;
1214 int res = PMINFO_R_OK;
1215 char* pAppId = null;
1216 ArrayList* pList = (ArrayList*)pUserData;
1218 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1219 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1221 SysLog(NID_APP, "appId = [%s]", pAppId);
1223 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1224 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1226 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1227 r = pPackageAppInfoImpl->Construct(pAppId);
1228 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1230 pList->Add(*pPackageAppInfo.release());
1235 _PackageManagerImpl*
1236 _PackageManagerImpl::GetInstance(void)
1238 return PackageManager::GetInstance()->__pPackageManagerImpl;
1242 _PackageManagerImpl::Construct(void)
1246 result r = __installationList.Construct();
1247 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
1252 _PackageManagerImpl::_PackageManagerImpl(void)
1253 :__pRequestClient(null),
1254 __pListeningClient(null)
1258 _PackageManagerImpl::~_PackageManagerImpl(void)
1263 _PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
1265 result r = E_SUCCESS;
1266 bool install = true;
1268 if (strcmp(pEventKey, "start") == 0)
1270 if ((strcmp(pEventValue, "install") == 0) || (strcmp(pEventValue, "uninstall") == 0))
1272 String* pAppId = new (std::nothrow) String(packageId);
1273 SysTryReturnVoidResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId instance must not be null.");
1275 String* pOperation = new (std::nothrow) String(pEventValue);
1276 SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null.");
1278 r = __installationList.Add(*pAppId, *pOperation);
1283 SysLog(NID_APP, "Failed to add installation condition.");
1284 SetLastResult(E_SYSTEM);
1289 else if (strcmp(pEventKey, "end") == 0)
1291 String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
1294 if (pOperation->Equals("uninstall", true) == true)
1299 r = __installationList.Remove(packageId, true);
1302 SysLogException(NID_APP, r, "[%s] Remove Element [%ls] is failed from installing list.", GetErrorMessage(r), packageId.GetPointer());
1307 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
1308 SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
1310 while (pEnum->MoveNext() == E_SUCCESS)
1312 _PackageManagerEvent* pEvent = null;
1313 pEnum->GetCurrent(pEvent);
1316 _PackageManagerEventArg* pEventArg= new (std::nothrow) _PackageManagerEventArg();
1317 SysTryReturnVoidResult(NID_APP, pEventArg, E_OUT_OF_MEMORY, "The memory is insufficient.");
1319 String eventKey(pEventKey);
1320 String eventValue(pEventValue);
1322 pEventArg->__packageId = packageId;
1323 pEventArg->__eventKey = eventKey;
1324 pEventArg->__eventValue = eventValue;
1325 pEventArg->__install = install;
1327 r = pEvent->Fire(*pEventArg);
1330 SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r));
1333 SysLog(NID_APP, "PackageId = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install);
1337 SysLog(NID_APP, "pEvent is null.");
1343 _PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const
1345 SysTryReturn(NID_APP, packageName.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageName is empty.");
1347 result r = E_SUCCESS;
1349 DbStatement* pStmt = null;
1350 DbEnumerator* pEnum = null;
1352 PackageInfo *pPackageInfo = null;
1354 query.Format( 1024, L"SELECT PkgInfo.*, AppInfo.APP_MAINMENU_ICON FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
1356 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1357 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1359 pStmt = CreateStatementN(db, query);
1361 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1363 pEnum = ExecuteStatementN(db, pStmt);
1366 if (pEnum->MoveNext() == E_SUCCESS)
1368 pPackageInfo = new (std::nothrow) PackageInfo;
1369 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
1371 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
1377 String appApiVersion;
1380 String appDescription;
1384 int appStorageType = 0;
1385 DateTime appInstallationTime;
1388 pEnum->GetStringAt(1, id);
1389 pEnum->GetStringAt(3, appVersion);
1390 pEnum->GetStringAt(4, appType);
1391 pEnum->GetStringAt(5, appMimeType);
1392 pEnum->GetStringAt(6, appApiVersion);
1393 pEnum->GetStringAt(7, appName);
1394 pEnum->GetStringAt(8, appVendor);
1395 pEnum->GetStringAt(9, appDescription);
1396 pEnum->GetStringAt(10, appUrl);
1397 pEnum->GetStringAt(11, appCid);
1398 pEnum->GetStringAt(16, appRootPath);
1399 pEnum->GetIntAt(17, appStorageType);
1400 pEnum->GetDateTimeAt(18, appInstallationTime);
1401 pEnum->GetStringAt(21, appIconPath);
1403 pPackageInfoImpl->SetAppId(id);
1404 pPackageInfoImpl->SetAppVersion(appVersion);
1405 pPackageInfoImpl->SetAppMimeType(appMimeType);
1406 pPackageInfoImpl->SetAppApiVersion(appApiVersion);
1407 pPackageInfoImpl->SetAppName(appName);
1408 pPackageInfoImpl->SetAppVendor(appVendor);
1409 pPackageInfoImpl->SetAppDescription(appDescription);
1410 pPackageInfoImpl->SetAppUrl(appUrl);
1411 pPackageInfoImpl->SetAppCid(appCid);
1412 pPackageInfoImpl->SetAppRootPath(appRootPath);
1413 pPackageInfoImpl->SetAppStorageType(appStorageType);
1414 pPackageInfoImpl->SetAppInstallationTime(appInstallationTime);
1415 pPackageInfoImpl->SetAppIconPath(appIconPath);
1422 r = E_OBJ_NOT_FOUND;
1427 return pPackageInfo;
1431 _PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1433 SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null.");
1436 char* pPackage = null;
1437 ArrayList* pList = (ArrayList*)pUserData;
1439 PackageInfo *pPackageInfo = new (std::nothrow) PackageInfo;
1440 SysTryReturn(NID_APP, pPackageInfo != null, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
1442 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
1444 result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage);
1447 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname(): package = [%s]", pPackage);
1451 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result);
1454 pPackageInfoImpl->Construct(pPackage);
1455 pList->Add(*pPackageInfo);
1461 _PackageManagerImpl::GetFilteredAppIdListN(const String& feature, const String& value) const
1463 result r = E_SUCCESS;
1465 DbStatement* pStmt = null;
1466 DbEnumerator* pEnum = null;
1468 ArrayList* pList = null;
1470 query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, AppFeature WHERE AppFeature.ID = AppInfo.UNIQUE_ID and AppFeature.NAME = '%ls' and AppFeature.VALUE = '%ls' COLLATE NOCASE", feature.GetPointer(), value.GetPointer());
1472 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1473 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1475 pStmt = CreateStatementN(db, query);
1476 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1478 pEnum = ExecuteStatementN(db, pStmt);
1482 pList = new (std::nothrow) ArrayList();
1483 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1486 while (pEnum->MoveNext() == E_SUCCESS)
1488 String* pPackageName = new (std::nothrow) String;
1489 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1491 pEnum->GetStringAt(0, *pPackageName);
1493 pList->Add(*pPackageName);
1501 r = E_OBJ_NOT_FOUND;
1510 _PackageManagerImpl::GetDataControlInfoN(const String& providerId, const String& type) const
1512 result r = E_SUCCESS;
1514 DbStatement* pStmt = null;
1515 DbEnumerator* pEnum = null;
1517 ArrayList* pList = null;
1519 query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME, DataControl.ACCESS FROM AppInfo, DataControl WHERE DataControl.ID = AppInfo.UNIQUE_ID and DataControl.PROVIDER_ID = '%ls' and DataControl.TYPE = '%ls' COLLATE NOCASE", providerId.GetPointer(), type.GetPointer());
1521 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1522 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1524 pStmt = CreateStatementN(db, query);
1525 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1527 pEnum = ExecuteStatementN(db, pStmt);
1531 pList = new (std::nothrow) ArrayList();
1532 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1535 while (pEnum->MoveNext() == E_SUCCESS)
1537 String* pPackageName = new (std::nothrow) String;
1538 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1540 String* pAccess = new (std::nothrow) String;
1541 SysTryReturn(NID_APP, pAccess != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pAccess instance must not be null.");
1543 pEnum->GetStringAt(0, *pPackageName);
1544 pList->Add(*pPackageName);
1546 pEnum->GetStringAt(1, *pAccess);
1547 pList->Add(*pAccess);
1555 r = E_OBJ_NOT_FOUND;
1564 _PackageManagerImpl::GetUiThemeListN(const PackageId& packageId) const
1566 result r = E_SUCCESS;
1568 DbStatement* pStmt = null;
1569 DbEnumerator* pEnum = null;
1571 HashMap* pList = null;
1573 query.Format(1024, L"SELECT AppFeature.NAME, AppFeature.VALUE FROM PkgInfo, AppInfo, AppFeature WHERE (AppFeature.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls') and (AppFeature.NAME = 'SystemTheme' or AppFeature.NAME = 'UserDefinedTheme')"
1574 , packageId.GetPointer());
1576 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1577 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1579 pStmt = CreateStatementN(db, query);
1580 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1582 pEnum = ExecuteStatementN(db, pStmt);
1586 pList = new (std::nothrow) HashMap();
1587 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
1590 while (pEnum->MoveNext() == E_SUCCESS)
1592 String* pName = new (std::nothrow) String;
1593 SysTryCatch(NID_APP, pName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pName instance must not be null.");
1595 String* pValue = new (std::nothrow) String;
1596 SysTryCatch(NID_APP, pValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pValue instance must not be null.");
1598 pEnum->GetStringAt(0, *pName);
1599 pEnum->GetStringAt(1, *pValue);
1601 pList->Add(*pName, *pValue);
1609 r = E_OBJ_NOT_FOUND;
1618 _PackageManagerImpl::IsAppInstalled(const AppId& appId)
1620 if (appId == _AppInfo::GetPackageId())
1626 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
1628 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(appId));
1629 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
1631 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
1632 SysTryReturn(NID_APP, result == 0, false, E_APP_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", result, pPackageId.get());
1634 if(pPackageInfoHandle)
1636 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
1643 _PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name,
1644 const char* key, const char* val, const void* pmsg, void* data)
1646 SysLog(NID_APP, "PackageEventHandler - req_id: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type,
1647 pkg_name, key, val);
1649 PackageType type = PACKAGE_TYPE_TPK;
1650 PackageId packageId(pkg_name);
1652 if (strcmp(pkg_type, "tpk") == 0)
1654 type = PACKAGE_TYPE_TPK;
1656 else if (strcmp(pkg_type, "wgt") == 0)
1658 type = PACKAGE_TYPE_WGT;
1662 SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type);
1666 _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance();
1667 pThis->SendPackageEvent(type, packageId, key, val);
1673 _PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId)
1675 result r = E_SUCCESS;
1677 DbStatement* pStmt = null;
1678 DbEnumerator* pEnum = null;
1680 String* pAppId = null;
1682 query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID",
1683 providerId.GetPointer());
1685 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1686 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1688 pStmt = CreateStatementN(db, query);
1689 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1691 pEnum = ExecuteStatementN(db, pStmt);
1695 if (pEnum->MoveNext() == E_SUCCESS)
1697 pAppId = new (std::nothrow) String;
1698 SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
1700 pEnum->GetStringAt(0, *pAppId);
1712 _PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
1714 result r = E_SUCCESS;
1715 PackageInfo* pPkgInfo = null;
1717 DbStatement* pStmt = null;
1718 DbEnumerator* pEnum = null;
1721 query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
1722 "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
1723 "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
1724 "GROUP BY AppInfoID"
1725 , providerId.GetPointer(), operationId.GetPointer());
1727 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1728 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1730 pStmt = CreateStatementN(db, query);
1731 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1733 pEnum = ExecuteStatementN(db, pStmt);
1736 if (pEnum->MoveNext() == E_SUCCESS)
1738 PackageId packageId;
1739 pEnum->GetStringAt(0, packageId);
1741 pPkgInfo = GetPackageInfoN(packageId);
1748 r = E_OBJ_NOT_FOUND;
1757 _PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
1759 result r = E_SUCCESS;
1761 DbStatement* pStmt = null;
1762 DbEnumerator* pEnum = null;
1765 PackageInfo* pPkgInfo = null;
1766 _PackageInfoImpl* pPackageInfoImpl = null;
1767 ArrayList* pList = null;
1769 pPkgInfo = GetPackageInfoN(packageId);
1770 SysTryCatch(NID_APP, pPkgInfo != null, , r, "[%s] GetPackageInfoN() is failed", GetErrorMessage(r));
1772 pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo);
1773 query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId());
1775 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1776 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1778 pStmt = CreateStatementN(db, query);
1779 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1780 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1782 pEnum = ExecuteStatementN(db, pStmt);
1786 pList = new (std::nothrow) ArrayList;
1787 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
1791 while (pEnum->MoveNext() == E_SUCCESS)
1793 _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl;
1794 SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null.");
1800 String mainmenuIcon;
1802 String quickpanelIcon;
1806 pEnum->GetIntAt(0, uniqueId);
1807 pEnum->GetIntAt(1, pkgId);
1808 pEnum->GetStringAt(2, name);
1809 pEnum->GetStringAt(3, defaultapp);
1810 pEnum->GetStringAt(4, mainmenuIcon);
1811 pEnum->GetStringAt(5, settingIcon);
1812 pEnum->GetStringAt(7, quickpanelIcon);
1813 pEnum->GetIntAt(9, appFeature);
1814 pEnum->GetStringAt(10, packageName);
1816 pPackageAppInfoImpl->SetUniqueId(uniqueId);
1817 pPackageAppInfoImpl->SetPkgId(pkgId);
1818 pPackageAppInfoImpl->SetName(name);
1819 pPackageAppInfoImpl->SetDefault(defaultapp);
1820 pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon);
1821 pPackageAppInfoImpl->SetSettingIcon(settingIcon);
1822 pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon);
1823 pPackageAppInfoImpl->SetAppFeature(appFeature);
1824 pPackageAppInfoImpl->SetPackageName(packageName);
1826 pList->Add(*pPackageAppInfoImpl);
1839 _PackageManagerImpl::GetPackageAppFeatureListN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const
1841 ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId);
1842 SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null.");
1844 ArrayList* pResult = null;
1846 for (int i = 0; i < pAppInfoList->GetCount(); i++)
1848 const _PackageAppInfoImpl* pAppInfoImpl = static_cast<const _PackageAppInfoImpl*>(pAppInfoList->GetAt(i));
1849 if (pAppInfoImpl == null)
1854 if (pAppInfoImpl->GetName() == appExecutableName)
1856 pResult = pAppInfoImpl->GetAppFeatureListN();
1862 pAppInfoList->RemoveAll(true);
1863 delete pAppInfoList;
1868 HashMapT<String, _AppFeatureInfoImpl*>*
1869 _PackageManagerImpl::GetPackageAppFeatureMapN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const
1871 ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId);
1872 SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null.");
1874 HashMapT<String, _AppFeatureInfoImpl*>* pResult = null;
1876 std::auto_ptr<IEnumerator> pEnum(pAppInfoList->GetEnumeratorN());
1878 while (pEnum->MoveNext() == E_SUCCESS)
1880 const _PackageAppInfoImpl* pAppInfoImpl = static_cast<const _PackageAppInfoImpl*>(pEnum->GetCurrent());
1881 if (pAppInfoImpl == null)
1886 if (pAppInfoImpl->GetName() == appExecutableName)
1888 pResult = pAppInfoImpl->GetAppFeatureMapN();
1894 pAppInfoList->RemoveAll(true);
1895 delete pAppInfoList;
1901 _PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const
1903 result r = E_SUCCESS;
1905 DbStatement* pStmt = null;
1906 DbEnumerator* pEnum = null;
1908 ArrayList* pList = null;
1910 query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
1912 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1913 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1915 pStmt = CreateStatementN(db, query);
1916 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1917 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1919 pEnum = ExecuteStatementN(db, pStmt);
1922 pList = new (std::nothrow) ArrayList;
1923 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
1927 while (pEnum->MoveNext() == E_SUCCESS)
1929 _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl;
1930 SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null.");
1935 pEnum->GetStringAt(1, name);
1936 pEnum->GetStringAt(2, value);
1938 pLaunchCondtion->SetName(name);
1939 pLaunchCondtion->SetValue(value);
1941 pList->Add(*pLaunchCondtion);
1943 SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer());
1955 _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pName, char* pPackageName, int bufferSize)
1957 result r = E_SUCCESS;
1959 DbStatement* pStmt = null;
1960 DbEnumerator* pEnum = null;
1962 Tizen::Base::String packageName;
1968 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
1969 "True", packageId.GetPointer());
1975 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and APP_NAME = '%ls' and PkgInfo.PKG_ID = '%ls'",
1976 pName->GetPointer(), packageId.GetPointer());
1979 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1980 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1982 pStmt = CreateStatementN(db, query);
1983 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1984 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1986 pEnum = ExecuteStatementN(db, pStmt);
1989 if (pEnum->MoveNext() == E_SUCCESS)
1991 pEnum->GetStringAt(0, packageName);
1992 snprintf(pPackageName, bufferSize, "%ls", packageName.GetPointer());
1998 r = E_OBJ_NOT_FOUND;
2008 _PackageManagerImpl::GetDefaultAppExecutableName(const PackageId& packageId)
2010 result r = E_SUCCESS;
2012 DbStatement* pStmt = null;
2013 DbEnumerator* pEnum = null;
2015 String executableName;
2019 L"SELECT AppInfo.APP_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2020 "True", packageId.GetPointer());
2022 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2023 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2025 pStmt = CreateStatementN(db, query);
2026 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2027 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2029 pEnum = ExecuteStatementN(db, pStmt);
2032 if (pEnum->MoveNext() == E_SUCCESS)
2034 pEnum->GetStringAt(0, executableName);
2040 r = E_OBJ_NOT_FOUND;
2047 return executableName;
2051 _PackageManagerImpl::CreateStatementN(Database& db, const String& query)
2053 result r = E_SUCCESS;
2054 DbStatement* pStmt = null;
2056 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2058 pStmt = db.CreateStatementN(query);
2059 r = GetLastResult();
2061 if (r != E_OBJECT_LOCKED)
2067 SysLog(NID_APP, "RetryCount[%d] CreateStatementN - E_OBJECT_LOCKED", i);
2078 _PackageManagerImpl::ExecuteStatementN(Database& db, const DbStatement* pStmt)
2080 result r = E_SUCCESS;
2081 DbEnumerator* pEnum = null;
2083 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2085 pEnum = db.ExecuteStatementN(*pStmt);
2086 r = GetLastResult();
2088 if (r != E_OBJECT_LOCKED)
2094 SysLog(NID_APP, "RetryCount[%d] ExecuteStatementN - E_OBJECT_LOCKED", i);
2104 } } } // Tizen::App::Package