2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FAppPkg_PackageManagerImpl.cpp
18 * @brief This is the implementation for the _PackageManagerImpl class.
26 #include <unique_ptr.h>
28 #include <package-manager-types.h>
30 #include <FAppPkgPackageManager.h>
31 #include <FAppPkgPackageAppInfo.h>
32 #include <FAppPkgPackageInfo.h>
33 #include <FAppPkgIPackageInstallationEventListener.h>
34 #include <FAppPkgIPackageInstallationResponseListener.h>
35 #include <FAppPkgIPackageUninstallationResponseListener.h>
36 #include <FBaseSysLog.h>
38 #include <FIoRegistry.h>
39 #include <FSecPrivilegeInfo.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::Base::Utility;
54 using namespace Tizen::Io;
55 using namespace Tizen::Security;
56 using namespace Tizen::System;
58 namespace Tizen { namespace App { namespace Package
61 PackageManager* pPackageManagerInstance = null;
63 Tizen::Base::Collection::HashMap _PackageManagerImpl::__installationList;
66 _PackageManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
68 IPackageInstallationEventListener* pListener = dynamic_cast<IPackageInstallationEventListener*> (&listener);
69 SysTryReturnVoidResult(NID_APP, pListener != null, E_OUT_OF_MEMORY, "pListener instance must not be null.");
71 const _PackageManagerEventArg* pArg = dynamic_cast<const _PackageManagerEventArg*>(&arg);
72 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "pArg instance must not be null.");
74 if (pArg->__eventKey == L"end")
76 if (pArg->__eventValue == L"ok")
80 SysLog(NID_APP, "Installation is Completed. [Package = %ls]", pArg->__packageId.GetPointer());
81 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
85 SysLog(NID_APP, "Uninstallation is Completed. [Package = %ls]", pArg->__packageId.GetPointer());
86 pListener->OnPackageUninstallationCompleted(pArg->__packageId, true);
91 if (pArg->__install == false)
93 SysLog(NID_APP, "Uninstallation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
94 pListener->OnPackageUninstallationCompleted(pArg->__packageId, false);
98 else if (pArg->__eventKey == L"error")
102 if (pArg->__eventValue == L"62")
104 SysLog(NID_APP, "Installation is Completed(Error = STORAGE_FULL(62)). [Package = %ls]", pArg->__packageId.GetPointer());
105 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_STORAGE_FULL);
109 SysLog(NID_APP, "Installation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
110 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
114 else if (pArg->__eventKey == L"install_percent")
116 std::unique_ptr<char[]> pProgress(_StringConverter::CopyToCharArrayN(pArg->__eventValue));
119 sscanf(pProgress.get(), "%d", &progress);
121 SysLog(NID_APP, "InstallationInProgress [%d]", progress);
122 pListener->OnPackageInstallationInProgress(pArg->__packageId, progress);
127 _PackageManagerImpl::GetPackageIdByAppId(const AppId& appId)
129 SysTryReturn(NID_APP, appId.IsEmpty() == false, L"", E_INVALID_ARG, "appId is empty");
133 char* pPackageId = null;
134 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
136 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
137 SysTryReturn(NID_APP, pAppId, L"", E_OUT_OF_MEMORY, "pAppId is null");
139 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
140 SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
142 result = pkgmgrinfo_appinfo_get_pkgname(pAppInfoHandle, &pPackageId);
144 packageId.Append(pPackageId);
148 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
151 SysLog(NID_APP, "app = [%ls], package = [%ls]", appId.GetPointer(), packageId.GetPointer());
157 _PackageManagerImpl::AddEventListener(IPackageInstallationEventListener* pListener, int priority)
159 SysTryReturnResult(NID_APP, (priority < 3) && (priority >= 0), E_INVALID_ARG, "priority is invalid.");
161 result r = E_SUCCESS;
164 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
165 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
167 while (pEnum->MoveNext() == E_SUCCESS)
169 _PackageManagerEvent* pEvent = null;
170 pEnum->GetCurrent(pEvent);
173 if (pEvent->__pListener == pListener)
175 SysLog(NID_APP, "The event listener already exist. listener = [0x%x]", pListener);
176 return E_OBJ_ALREADY_EXIST;
181 if (__pListeningClient == null)
183 __pListeningClient = pkgmgr_client_new(PC_LISTENING);
184 SysTryReturnResult(NID_APP, __pListeningClient != null, E_SYSTEM, "pkgmgr_client_new(PC_LISTENING) failed");
186 res = pkgmgr_client_listen_status(__pListeningClient, PackageEventHandler, this);
187 if (res < PKGMGR_R_OK)
189 pkgmgr_client_free(__pListeningClient);
190 __pListeningClient = null;
192 if (res == PKGMGR_R_EINVAL)
194 SysLog(NID_APP, "pkgmgr_client_listen_status() returns ARGV error");
195 return E_INVALID_ARG;
197 else if (res == PKGMGR_R_ECOMM)
199 SysLog(NID_APP, "pkgmgr_client_listen_status() returns COMM error");
201 else if (res == PKGMGR_R_ETIMEOUT)
203 SysLog(NID_APP, "pkgmgr_client_listen_status() returns TIME_OUT error");
205 else if (res == PKGMGR_R_ERROR)
207 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error");
211 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error, res = %d", res);
218 _PackageManagerEvent* pEvent = new (std::nothrow) _PackageManagerEvent();
219 SysTryReturnResult(NID_APP, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
221 r = pEvent->Construct();
222 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "pEvent->Construct() failed.");
224 pEvent->__pListener = pListener;
226 r = pEvent->AddListener(*pListener, true);
227 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "pEvent->AddListener() failed. [%s]", GetErrorMessage(r));
229 r = __packageEventListenerList.Add(pEvent);
230 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
232 SysLog(NID_APP, "Add PackageInstallationEventListener = [0x%x]", pListener);
237 _PackageManagerImpl::RemoveEventListener(IPackageInstallationEventListener* pListener)
239 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
240 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
242 result r = E_SUCCESS;
244 while (pEnum->MoveNext() == E_SUCCESS)
246 _PackageManagerEvent* pEvent = null;
247 pEnum->GetCurrent(pEvent);
250 if (pEvent->__pListener == pListener)
252 r = __packageEventListenerList.Remove(pEvent);
253 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
257 SysLog(NID_APP, "Remove PackageInstallationEventListener = [0x%x]", pListener);
263 return E_OBJ_NOT_FOUND;
267 _PackageManagerImpl::GetPackageInfoN(const PackageId& packageId) const
269 SysTryReturn(NID_APP, packageId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageId is empty.");
270 SysTryReturn(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, null, E_INVALID_ARG, "packageId is invalid.(length)");
272 result r = E_SUCCESS;
273 PackageInfo* pPackageInfo = null;
275 pPackageInfo = new (std::nothrow) PackageInfo;
276 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
278 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
279 r = pPackageInfoImpl->Construct(packageId);
280 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] package (%ls) is not found.", packageId.GetPointer());
290 _PackageManagerImpl::GetPackageAppInfoN(const AppId& appId) const
292 SysTryReturn(NID_APP, appId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
294 result r = E_SUCCESS;
295 PackageAppInfo* pPackageAppInfo = null;
297 pPackageAppInfo = new (std::nothrow) PackageAppInfo;
298 SysTryReturn(NID_APP, pPackageAppInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageAppInfo instance must not be null.");
300 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo);
301 r = pPackageAppInfoImpl->Construct(appId);
302 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] app (%ls) is not found.", appId.GetPointer());
304 return pPackageAppInfo;
307 delete pPackageAppInfo;
312 _PackageManagerImpl::GetPackageInfoListN(void) const
314 result r = E_SUCCESS;
316 ArrayList* pList = null;
318 pList = new (std::nothrow) ArrayList();
319 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
322 res = pkgmgrinfo_pkginfo_get_list(PackageInfoEventHandler, pList);
325 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_list() is failed. result = [%d]", res);
327 pList->RemoveAll(true);
336 _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
338 SysTryReturn(NID_APP, packageId.IsEmpty() == false, false, E_INVALID_ARG, "packageId is empty");
341 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
343 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
344 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
346 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
349 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
353 if(pPackageInfoHandle)
355 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
358 SysLog(NID_APP, "package = [%ls] is installed.", packageId.GetPointer());
364 _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& packagePath, IPackageInstallationResponseListener* pListener)
366 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
367 SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
368 SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
370 String extension = File::GetFileExtension(packagePath);
371 SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
373 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(packagePath));
374 SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null.");
376 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
377 SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null.");
379 if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
381 SysLog(NID_APP, "package = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
385 SysLog(NID_APP, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
389 // optionalData = 12345abcde
391 optionalData.Append(packageId);
393 std::unique_ptr<char[]> pOptionalData(_StringConverter::CopyToCharArrayN(optionalData));
394 SysTryReturnResult(NID_APP, pOptionalData, E_OUT_OF_MEMORY, "pOptionalData is null.");
396 SysLog(NID_APP, "optionalData = [%s]", pOptionalData.get());
398 result r = E_SUCCESS;
399 _PackageManagerProxy packageManagerProxy;
400 r = packageManagerProxy.Construct();
401 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
403 r = packageManagerProxy.InstallPackage(packageId, packagePath, null);
404 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.InstallPackage() failed.");
406 if (__pRequestClient == null)
408 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
409 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
412 int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), pOptionalData.get(), PM_QUIET, InstallationEventHandler, pListener);
414 if (res < PKGMGR_R_OK)
416 pkgmgr_client_free(__pRequestClient);
417 __pRequestClient = null;
419 if (res == PKGMGR_R_EINVAL)
421 SysLog(NID_APP, "pkgmgr_client_install() returns ARGV error");
422 return E_INVALID_ARG;
424 else if (res == PKGMGR_R_ECOMM)
426 SysLog(NID_APP, "pkgmgr_client_install() returns COMM error");
428 else if (res == PKGMGR_R_ETIMEOUT)
430 SysLog(NID_APP, "pkgmgr_client_install() returns TIME_OUT error");
432 else if (res == PKGMGR_R_ERROR)
434 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error");
438 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error, res = %d", res);
448 _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener)
450 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
451 SysTryReturnResult(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The packageId is invalid.(length)");
452 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
454 result r = E_SUCCESS;
457 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
459 _PackageManagerProxy packageManagerProxy;
460 r = packageManagerProxy.Construct();
461 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
463 r = packageManagerProxy.UninstallPackage(packageId, pListener);
464 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.UninstallPackage() failed.");
466 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
467 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
469 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
470 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
472 res = pkgmgrinfo_pkginfo_get_type(pPackageInfoHandle, &pType);
473 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
475 if (__pRequestClient == null)
477 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
478 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
481 res = pkgmgr_client_uninstall(__pRequestClient, pType, pPackageId.get(), PM_QUIET, UninstallationEventHandler, pListener);
482 SysLog(NID_APP, "pkgmgr_client_uninstall - req=[%d], package=[%s], type=[%s]", res, pPackageId.get(), pType);
484 if(pPackageInfoHandle)
486 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
489 if (res < PKGMGR_R_OK)
491 pkgmgr_client_free(__pRequestClient);
492 __pRequestClient = null;
494 if (res == PKGMGR_R_EINVAL)
496 SysLog(NID_APP, "pkgmgr_client_uninstall() returns ARGV error");
497 return E_INVALID_ARG;
499 else if (res == PKGMGR_R_ECOMM)
501 SysLog(NID_APP, "pkgmgr_client_uninstall() returns COMM error");
503 else if (res == PKGMGR_R_ETIMEOUT)
505 SysLog(NID_APP, "pkgmgr_client_uninstall() returns TIME_OUT error");
507 else if (res == PKGMGR_R_ERROR)
509 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error");
513 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error, res = %d", res);
523 _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId)
525 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
526 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
530 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
531 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
533 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
534 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
536 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
537 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
539 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
540 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
542 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
543 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
545 if (storage == PMINFO_EXTERNAL_STORAGE)
547 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
548 return E_INVALID_OPERATION;
551 if (__pRequestClient == null)
553 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
554 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
557 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, %s, %s)", pType, pPackageId.get());
558 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, __pRequestClient, pType, pPackageId.get(), null, null, null);
560 if (packageInfoHandle)
562 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
565 if (res < PKGMGR_R_OK)
567 pkgmgr_client_free(__pRequestClient);
568 __pRequestClient = null;
570 if (res == PKGMGR_R_EINVAL)
572 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
573 return E_INVALID_ARG;
575 else if (res == PKGMGR_R_ERROR)
577 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
581 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
591 _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
593 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
594 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
598 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
599 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
601 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
602 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
604 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
605 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
607 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
608 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
610 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
611 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
613 if (storage == PMINFO_INTERNAL_STORAGE)
615 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
616 return E_INVALID_OPERATION;
619 if (__pRequestClient == null)
621 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
622 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
625 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, %s, %s)", pType, pPackageId.get());
626 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, __pRequestClient, pType, pPackageId.get(), null, null, null);
628 if (packageInfoHandle)
630 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
633 if (res < PKGMGR_R_OK)
635 pkgmgr_client_free(__pRequestClient);
636 __pRequestClient = null;
638 if (res == PKGMGR_R_EINVAL)
640 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
641 return E_INVALID_ARG;
643 else if (res == PKGMGR_R_ERROR)
645 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
649 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
659 _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
661 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
665 IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData;
667 if (strcmp(pKey, "end") == 0)
669 if (strcmp(pVal, "ok") == 0)
671 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
672 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_SUCCESS)");
677 else if (strcmp(pKey, "error") == 0)
679 if (strcmp(pVal, "62") == 0)
681 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_STORAGE_FULL);
682 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_STORAGE_FULL)");
686 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
687 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE)");
690 else if (strcmp(pKey, "install_percent") == 0)
693 sscanf(pVal, "%d", &progress);
695 pListener->OnPackageInstallationInProgressResponseReceived(pPackageId, progress);
696 SysLog(NID_APP, "OnPackageInstallationInProgressResponseReceived(%s, %d)", pPackageId, progress);
704 _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
706 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
710 if (strcmp(pKey, "end") == 0)
712 IPackageUninstallationResponseListener* pListener = (IPackageUninstallationResponseListener*) pData;
714 if (strcmp(pVal, "ok") == 0)
716 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(true)");
717 pListener->OnPackageUninstallationResponseReceived(pPackageId, true);
721 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(false)");
722 pListener->OnPackageUninstallationResponseReceived(pPackageId, false);
733 _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
735 SysTryReturn(NID_APP, filePath.IsEmpty() == false, null, E_INVALID_ARG, "filePath is empty.");
736 SysTryReturn(NID_APP, File::IsFileExist(filePath) == true, null, E_FILE_NOT_FOUND, "package is not existed.");
738 String extension = File::GetFileExtension(filePath);
739 SysTryReturn(NID_APP, extension.IsEmpty() == false, null, E_INVALID_ARG, "extension is empty.");
741 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(filePath));
742 SysTryReturn(NID_APP, pPackagePath, null, E_OUT_OF_MEMORY, "pPackagePath is null.");
744 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
745 SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null.");
747 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
748 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
750 SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
754 if (strcasecmp(pExtension.get(), "tpk") == 0)
756 _PackageParser packageParser;
758 res = packageParser.Construct(pPackageInfo.get());
759 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
761 res = packageParser.Parse(filePath);
762 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
764 else if (strcasecmp(pExtension.get(), "wgt") == 0)
766 pkgmgr_info* pPkgmgrInfo = null;
768 pPkgmgrInfo = pkgmgr_client_check_pkginfo_from_file(pPackagePath.get());
769 SysTryReturn(NID_APP, pPkgmgrInfo, null, E_PARSING_FAILED, "pkgmgr_client_check_pkginfo_from_file(%s) is failed.", pPackagePath.get());
771 _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo;
772 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
774 SysLog(NID_APP, "package(%s), version(%s), label(%s), description(%s), author(%s), icon_size(%d), pkgname(%s)", pPkgInfo->pkgid, pPkgInfo->version, pPkgInfo->label,
775 pPkgInfo->pkg_description, pPkgInfo->author, pPkgInfo->icon_size, pPkgInfo->pkg_name);
777 pPackageInfoImpl->SetType(PACKAGE_TYPE_WGT);
778 pPackageInfoImpl->SetId(pPkgInfo->pkgid);
779 pPackageInfoImpl->SetVersion(pPkgInfo->version);
780 pPackageInfoImpl->SetDisplayName(pPkgInfo->label);
781 pPackageInfoImpl->SetDescription(pPkgInfo->pkg_description);
782 pPackageInfoImpl->SetAuthor(pPkgInfo->author);
783 pPackageInfoImpl->SetMainAppId(pPkgInfo->pkg_name);
785 if (IsHybridPackage(filePath) == true)
787 PackageInfo hybridServiceInfo;
788 _PackageParser packageParser;
790 res = packageParser.Construct(&hybridServiceInfo);
791 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
793 res = packageParser.Parse(filePath);
794 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
796 IList* pList = hybridServiceInfo.GetPrivilegeListN();
799 for (int i = 0; i < pList->GetCount(); i++)
801 PrivilegeInfo* pPrivilegeInfo = dynamic_cast < PrivilegeInfo* >(pList->GetAt(i));
804 String privilege = pPrivilegeInfo->GetId();
805 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(privilege));
806 SysLog(NID_APP, "privilege[%ls] is added for hybrid.", privilege.GetPointer());
812 if (pPkgInfo->privilege_list)
815 pList = g_list_first(pPkgInfo->privilege_list);
818 char* pPrivilege = (char*)pList->data;
821 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege));
824 pList = g_list_next(pList);
826 g_list_free(pPkgInfo->privilege_list);
829 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
832 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
834 pPackageAppInfoImpl->SetAppId(pPkgInfo->pkg_name);
835 pPackageAppInfoImpl->SetAppName(pPkgInfo->label);
836 pPackageAppInfoImpl->SetAppDisplayName(pPkgInfo->label);
837 pPackageAppInfoImpl->SetMainApp(true);
838 if ((pPkgInfo->icon_buf) && (pPkgInfo->icon_size > 0))
840 pPackageAppInfoImpl->SetAppMenuIconBuffer(pPkgInfo->icon_buf, pPkgInfo->icon_size);
843 pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release());
847 SysLog(NID_APP, "pPackageAppInfo instance must not be null.");
848 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
852 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
856 SysTryReturn(NID_APP, false, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
859 SetLastResult(E_SUCCESS);
860 return pPackageInfo.release();
864 _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
866 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
868 std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
869 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
871 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
872 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
876 int res = PMINFO_R_OK;
877 pkgmgrinfo_pkginfo_filter_h handle = null;
879 res = pkgmgrinfo_pkginfo_filter_create(&handle);
880 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
882 while(pEnum->MoveNext() == E_SUCCESS)
884 String* pKey = static_cast< String* >(pEnum->GetKey());
885 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
887 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
888 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
890 bool value = pVal->ToBool();
892 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
894 if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
896 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
897 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
899 else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
901 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
902 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
904 else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
906 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
907 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
909 else if ((*pKey) == PACKAGE_FILTER_TPK)
911 SysTryCatch(NID_APP, value == true, , E_SYSTEM, "Value(false) is invalid for PACKAGE_FILTER_TPK.");
913 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "tpk");
914 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(TYPE, tpk) is failed. [%d]", res);
916 else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
918 String installedStorage;
921 installedStorage = L"installed_external";
925 installedStorage = L"installed_internal";
928 std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
929 SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
931 SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
933 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
934 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
938 SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
942 res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList.get());
943 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed. [%d]", res);
948 pkgmgrinfo_pkginfo_filter_destroy(handle);
951 if (pList->GetCount() <= 0)
953 SysLog(NID_APP, "pList's count is 0.");
957 return pList.release();
961 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) const
963 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
965 std::unique_ptr< IMapEnumerator > pEnum(packageAppFilterMap.GetMapEnumeratorN());
966 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
968 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
969 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
974 bool definedKey = false;
975 bool metadataKey = false;
977 ArrayList metadataList;
979 pkgmgrinfo_appinfo_filter_h handle = null;
980 pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null;
982 res = pkgmgrinfo_appinfo_filter_create(&handle);
983 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res);
985 res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle);
986 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res);
988 while(pEnum->MoveNext() == E_SUCCESS)
990 String* pKey = static_cast< String* >(pEnum->GetKey());
991 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
993 if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE)
997 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
998 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1000 bool nodisplay = !(pVal->ToBool());
1001 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), nodisplay);
1003 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, nodisplay);
1004 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(NODISPLAY, %d) is failed. [%d]", nodisplay, res);
1007 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_ONBOOT)
1011 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1012 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1014 bool value = pVal->ToBool();
1015 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1017 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, value);
1018 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(ONBOOT, %d) is failed. [%d]", value, res);
1020 else if ((*pKey) == PACKAGE_APP_FILTER_AUTO_RESTART)
1024 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1025 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1027 bool value = pVal->ToBool();
1028 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1030 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, value);
1031 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(AUTORESTART, %d) is failed. [%d]", value, res);
1034 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCHING_HISTORY_VISIBLE)
1038 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1039 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1041 bool value = pVal->ToBool();
1042 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1044 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, value);
1045 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(TASKMANAGE, %d) is failed. [%d]", value, res);
1047 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_CONDITION)
1051 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1052 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1054 bool value = pVal->ToBool();
1055 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1057 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, value);
1058 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(LAUNCHCONDITION, %d) is failed. [%d]", value, res);
1060 else if ((*pKey) == PACKAGE_APP_FILTER_CATEGORY_HOMEAPP || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_LOCKAPP
1061 || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_MENUAPP)
1065 std::unique_ptr<char[]> pDefinedKey(_StringConverter::CopyToCharArrayN(*pKey));
1066 SysTryCatch(NID_APP, pDefinedKey, , E_OUT_OF_MEMORY, "pDefinedKey is null.");
1068 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1069 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1071 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), pVal->ToBool());
1072 SysTryCatch(NID_APP, pVal->ToBool() == true, , E_INVALID_ARG, "Value(false) is not allowed.");
1074 res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pDefinedKey.get());
1075 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pDefinedKey.get(), res);
1081 String* pVal = static_cast< String* >(pEnum->GetValue());
1082 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1084 SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
1086 std::unique_ptr<char[]> pMetaKey(_StringConverter::CopyToCharArrayN(*pKey));
1087 SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null.");
1089 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
1090 SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
1092 if ((*pVal) == L"*")
1094 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), null);
1095 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, null) is failed. [%d]", pMetaKey.get(), res);
1099 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), pValue.get());
1100 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, %s) is failed. [%d]", pMetaKey.get(), pValue.get(), res);
1105 if ((definedKey == true) && (metadataKey == false))
1107 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList.get());
1108 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_foreach_appinfo() failed. [%d]", res);
1110 else if ((definedKey == false) && (metadataKey == true))
1112 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList.get());
1113 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_foreach() failed. [%d]", res);
1119 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list);
1120 if (res != PMINFO_R_OK)
1122 SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res);
1126 metadataList.Construct();
1128 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, &metadataList);
1129 if (res != PMINFO_R_OK)
1131 SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res);
1135 for (int i = 0; i < list.GetCount(); i++)
1137 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i));
1138 if (pPackageAppInfo)
1140 SysLog(NID_APP, "PackageAppFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1142 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1143 appIdList.Add(pAppId.release());
1147 for (int j = 0; j < metadataList.GetCount(); j++)
1149 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j));
1150 if (pPackageAppInfo)
1152 AppId appId = pPackageAppInfo->GetAppId();
1154 if (appIdList.Contains(appId) == true)
1156 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1158 std::unique_ptr< PackageAppInfo > pAppInfo(new (std::nothrow) PackageAppInfo);
1159 SysTryCatch(NID_APP, pAppInfo, , E_OUT_OF_MEMORY, "pAppInfo is null.");
1161 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
1162 pPackageAppInfoImpl->Construct(appId);
1164 pList->Add(pAppInfo.release());
1168 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1177 pkgmgrinfo_appinfo_filter_destroy(handle);
1182 pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle);
1185 if (pList->GetCount() <= 0)
1187 SysLog(NID_APP, "pList's count is 0.");
1191 return pList.release();
1195 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
1197 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap Count is invalid.");
1198 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap Count is invalid.");
1200 ArrayList appIdList;
1202 std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap));
1203 if (pPackageFilterList == null)
1205 SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null.");
1209 for (int i = 0; i < pPackageFilterList->GetCount(); i++)
1211 PackageInfo* pPackageInfo = dynamic_cast < PackageInfo* >(pPackageFilterList->GetAt(i));
1214 std::unique_ptr< IList > pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
1215 if (pPackageAppInfoList)
1217 for (int j = 0; j < pPackageAppInfoList->GetCount(); j++)
1219 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppInfoList->GetAt(j));
1220 if (pPackageAppInfo)
1222 SysLog(NID_APP, "PackageFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1224 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1225 appIdList.Add(pAppId.release());
1232 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList);
1233 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
1235 std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap));
1236 if (pAppFilterList == null)
1238 SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null.");
1242 for (int k = 0; k < pAppFilterList->GetCount(); k++)
1244 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k));
1245 if (pPackageAppInfo)
1247 AppId appId = pPackageAppInfo->GetAppId();
1248 SysLog(NID_APP, "AppFilter - App [%ls]", appId.GetPointer());
1250 if (appIdList.Contains(appId) == true)
1252 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1254 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1255 SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null.");
1257 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1258 pPackageAppInfoImpl->Construct(appId);
1260 pList->Add(pPackageAppInfo.release());
1264 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1269 if (pList->GetCount() <= 0)
1271 SysLog(NID_APP, "pList's count is 0.");
1275 return pList.release();
1279 _PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1281 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1282 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1284 result r = E_SUCCESS;
1285 int res = PMINFO_R_OK;
1286 char* pPackageId = null;
1287 ArrayList* pList = (ArrayList*)pUserData;
1289 res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
1290 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
1292 std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
1293 SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1295 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1296 r = pPackageInfoImpl->Construct(pPackageId);
1297 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
1299 pList->Add(*pPackageInfo.release());
1305 _PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1307 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1308 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1310 result r = E_SUCCESS;
1311 int res = PMINFO_R_OK;
1312 char* pAppId = null;
1313 ArrayList* pList = (ArrayList*)pUserData;
1315 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1316 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1318 SysLog(NID_APP, "app = [%s]", pAppId);
1320 std::unique_ptr<PackageAppInfo> pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1321 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1323 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1324 r = pPackageAppInfoImpl->Construct(pAppId);
1325 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1327 pList->Add(*pPackageAppInfo.release());
1333 _PackageManagerImpl::PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1335 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1336 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1338 result r = E_SUCCESS;
1339 int res = PMINFO_R_OK;
1340 char* pAppId = null;
1341 ArrayList* pList = (ArrayList*)pUserData;
1343 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1344 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1346 SysLog(NID_APP, "app = [%s]", pAppId);
1348 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1349 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1351 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1352 r = pPackageAppInfoImpl->Construct(pAppId);
1353 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1355 pList->Add(*pPackageAppInfo.release());
1361 _PackageManagerImpl::IsHybridPackage(const String& filePath) const
1363 SysTryReturn(NID_APP, filePath.IsEmpty() == false, false, E_INVALID_ARG, "filePath is empty.");
1366 FileUnzipper unzipper;
1369 result r = unzipper.Construct(filePath);
1370 SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.Construct() failed.");
1372 r = unzipper.GetEntry(L"info/manifest.xml", zipEntry);
1375 SysLog(NID_APP, "It's hybrid package. [%ls]", filePath.GetPointer());
1380 SysLog(NID_APP, "It's not hybrid package. [%ls]", filePath.GetPointer());
1384 SetLastResult(E_SUCCESS);
1388 _PackageManagerImpl*
1389 _PackageManagerImpl::GetInstance(void)
1391 return PackageManager::GetInstance()->__pPackageManagerImpl;
1395 _PackageManagerImpl::Construct(void)
1399 result r = __installationList.Construct();
1400 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
1405 _PackageManagerImpl::_PackageManagerImpl(void)
1406 :__pRequestClient(null),
1407 __pListeningClient(null)
1411 _PackageManagerImpl::~_PackageManagerImpl(void)
1416 _PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
1418 result r = E_SUCCESS;
1419 bool install = true;
1422 if (strcmp(pEventKey, "start") == 0)
1424 if ((strcmp(pEventValue, "install") == 0)
1425 || (strcmp(pEventValue, "update") == 0)
1426 ||(strcmp(pEventValue, "uninstall") == 0)
1427 ||(strcmp(pEventValue, "move") == 0))
1429 PackageId* pPackageId = new (std::nothrow) String(packageId);
1430 SysTryReturnVoidResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null.");
1432 String* pOperation = new (std::nothrow) String(pEventValue);
1433 SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation is null.");
1435 r = __installationList.Add(*pPackageId, *pOperation);
1440 SysLog(NID_APP, "Failed to add installation condition.");
1441 SetLastResult(E_SYSTEM);
1446 else if (strcmp(pEventKey, "end") == 0)
1448 String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
1449 SysTryReturnVoidResult(NID_APP, pOperation != null, E_SYSTEM, "pOperation is null.");
1451 if (pOperation->Equals("uninstall", true) == true)
1455 else if (pOperation->Equals("move", true) == true)
1460 r = __installationList.Remove(packageId, true);
1461 SysTryReturnVoidResult(NID_APP, !IsFailed(r), E_SYSTEM, "installationList.Remove(%ls) failed. (%s)", packageId.GetPointer(), GetErrorMessage(r));
1464 if ((strcmp(pEventValue, "move") == 0) || (move == true))
1466 SysLog(NID_APP, "Skip move event.");
1470 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
1471 SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
1473 while (pEnum->MoveNext() == E_SUCCESS)
1475 _PackageManagerEvent* pEvent = null;
1476 pEnum->GetCurrent(pEvent);
1479 _PackageManagerEventArg* pEventArg= new (std::nothrow) _PackageManagerEventArg();
1480 SysTryReturnVoidResult(NID_APP, pEventArg, E_OUT_OF_MEMORY, "The memory is insufficient.");
1482 String eventKey(pEventKey);
1483 String eventValue(pEventValue);
1485 pEventArg->__packageId = packageId;
1486 pEventArg->__eventKey = eventKey;
1487 pEventArg->__eventValue = eventValue;
1488 pEventArg->__install = install;
1490 r = pEvent->Fire(*pEventArg);
1493 SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r));
1496 SysLog(NID_APP, "Package = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install);
1500 SysLog(NID_APP, "pEvent is null.");
1506 _PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const
1508 SysTryReturn(NID_APP, packageName.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageName is empty.");
1510 result r = E_SUCCESS;
1512 DbStatement* pStmt = null;
1513 DbEnumerator* pEnum = null;
1515 PackageInfo *pPackageInfo = null;
1517 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());
1519 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1520 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1522 pStmt = CreateStatementN(db, query);
1524 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1526 pEnum = ExecuteStatementN(db, pStmt);
1529 if (pEnum->MoveNext() == E_SUCCESS)
1531 pPackageInfo = new (std::nothrow) PackageInfo;
1532 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
1534 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
1540 String appApiVersion;
1543 String appDescription;
1547 int appStorageType = 0;
1548 DateTime appInstallationTime;
1551 pEnum->GetStringAt(1, id);
1552 pEnum->GetStringAt(3, appVersion);
1553 pEnum->GetStringAt(4, appType);
1554 pEnum->GetStringAt(5, appMimeType);
1555 pEnum->GetStringAt(6, appApiVersion);
1556 pEnum->GetStringAt(7, appName);
1557 pEnum->GetStringAt(8, appVendor);
1558 pEnum->GetStringAt(9, appDescription);
1559 pEnum->GetStringAt(10, appUrl);
1560 pEnum->GetStringAt(11, appCid);
1561 pEnum->GetStringAt(16, appRootPath);
1562 pEnum->GetIntAt(17, appStorageType);
1563 pEnum->GetDateTimeAt(18, appInstallationTime);
1564 pEnum->GetStringAt(21, appIconPath);
1566 pPackageInfoImpl->SetAppId(id);
1567 pPackageInfoImpl->SetAppVersion(appVersion);
1568 pPackageInfoImpl->SetAppMimeType(appMimeType);
1569 pPackageInfoImpl->SetAppApiVersion(appApiVersion);
1570 pPackageInfoImpl->SetAppName(appName);
1571 pPackageInfoImpl->SetAppVendor(appVendor);
1572 pPackageInfoImpl->SetAppDescription(appDescription);
1573 pPackageInfoImpl->SetAppUrl(appUrl);
1574 pPackageInfoImpl->SetAppCid(appCid);
1575 pPackageInfoImpl->SetAppRootPath(appRootPath);
1576 pPackageInfoImpl->SetAppStorageType(appStorageType);
1577 pPackageInfoImpl->SetAppInstallationTime(appInstallationTime);
1578 pPackageInfoImpl->SetAppIconPath(appIconPath);
1585 r = E_OBJ_NOT_FOUND;
1590 return pPackageInfo;
1594 _PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1596 SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null.");
1598 result r = E_SUCCESS;
1600 char* pPackage = null;
1601 ArrayList* pList = (ArrayList*)pUserData;
1603 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
1604 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1606 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1608 result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage);
1611 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname(): package = [%s]", pPackage);
1615 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result);
1618 r = pPackageInfoImpl->Construct(pPackage);
1619 SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pPackageInfoImpl->Construct() failed.");
1621 r = pList->Add(*pPackageInfo.release());
1622 SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pList->Add() failed.");
1628 _PackageManagerImpl::GetFilteredAppIdListN(const String& feature, const String& value) const
1630 result r = E_SUCCESS;
1632 DbStatement* pStmt = null;
1633 DbEnumerator* pEnum = null;
1635 ArrayList* pList = null;
1637 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());
1639 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1640 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1642 pStmt = CreateStatementN(db, query);
1643 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1645 pEnum = ExecuteStatementN(db, pStmt);
1649 pList = new (std::nothrow) ArrayList();
1650 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1653 while (pEnum->MoveNext() == E_SUCCESS)
1655 String* pPackageName = new (std::nothrow) String;
1656 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1658 pEnum->GetStringAt(0, *pPackageName);
1660 pList->Add(*pPackageName);
1668 r = E_OBJ_NOT_FOUND;
1677 _PackageManagerImpl::GetDataControlInfoN(const String& providerId, const String& type) const
1679 result r = E_SUCCESS;
1681 DbStatement* pStmt = null;
1682 DbEnumerator* pEnum = null;
1684 ArrayList* pList = null;
1686 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());
1688 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1689 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1691 pStmt = CreateStatementN(db, query);
1692 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1694 pEnum = ExecuteStatementN(db, pStmt);
1698 pList = new (std::nothrow) ArrayList();
1699 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1702 while (pEnum->MoveNext() == E_SUCCESS)
1704 String* pPackageName = new (std::nothrow) String;
1705 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1707 String* pAccess = new (std::nothrow) String;
1708 SysTryReturn(NID_APP, pAccess != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pAccess instance must not be null.");
1710 pEnum->GetStringAt(0, *pPackageName);
1711 pList->Add(*pPackageName);
1713 pEnum->GetStringAt(1, *pAccess);
1714 pList->Add(*pAccess);
1722 r = E_OBJ_NOT_FOUND;
1731 _PackageManagerImpl::GetUiThemeListN(const PackageId& packageId) const
1733 result r = E_SUCCESS;
1735 DbStatement* pStmt = null;
1736 DbEnumerator* pEnum = null;
1738 HashMap* pList = null;
1740 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')"
1741 , packageId.GetPointer());
1743 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1744 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1746 pStmt = CreateStatementN(db, query);
1747 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1749 pEnum = ExecuteStatementN(db, pStmt);
1753 pList = new (std::nothrow) HashMap();
1754 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
1757 while (pEnum->MoveNext() == E_SUCCESS)
1759 String* pName = new (std::nothrow) String;
1760 SysTryCatch(NID_APP, pName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pName instance must not be null.");
1762 String* pValue = new (std::nothrow) String;
1763 SysTryCatch(NID_APP, pValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pValue instance must not be null.");
1765 pEnum->GetStringAt(0, *pName);
1766 pEnum->GetStringAt(1, *pValue);
1768 pList->Add(*pName, *pValue);
1776 r = E_OBJ_NOT_FOUND;
1785 _PackageManagerImpl::IsAppInstalled(const AppId& appId)
1787 SysTryReturn(NID_APP, appId.IsEmpty() == false, false, E_INVALID_ARG, "appId is empty.");
1790 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
1792 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1793 SysTryReturn(NID_APP, pAppId, false, E_OUT_OF_MEMORY, "pAppId is null.");
1795 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
1798 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
1804 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
1807 SysLog(NID_APP, "app = [%ls] is installed.", appId.GetPointer());
1813 _PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name,
1814 const char* key, const char* val, const void* pmsg, void* data)
1816 SysLog(NID_APP, "PackageEventHandler - req: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type,
1817 pkg_name, key, val);
1819 PackageType type = PACKAGE_TYPE_TPK;
1820 PackageId packageId(pkg_name);
1822 if (strcmp(pkg_type, "tpk") == 0)
1824 type = PACKAGE_TYPE_TPK;
1826 else if (strcmp(pkg_type, "wgt") == 0)
1828 type = PACKAGE_TYPE_WGT;
1832 SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type);
1836 _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance();
1837 pThis->SendPackageEvent(type, packageId, key, val);
1843 _PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId)
1845 result r = E_SUCCESS;
1847 DbStatement* pStmt = null;
1848 DbEnumerator* pEnum = null;
1850 String* pAppId = null;
1852 query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID",
1853 providerId.GetPointer());
1855 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1856 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1858 pStmt = CreateStatementN(db, query);
1859 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1861 pEnum = ExecuteStatementN(db, pStmt);
1865 if (pEnum->MoveNext() == E_SUCCESS)
1867 pAppId = new (std::nothrow) String;
1868 SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
1870 pEnum->GetStringAt(0, *pAppId);
1882 _PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
1884 result r = E_SUCCESS;
1885 PackageInfo* pPkgInfo = null;
1887 DbStatement* pStmt = null;
1888 DbEnumerator* pEnum = null;
1891 query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
1892 "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
1893 "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
1894 "GROUP BY AppInfoID"
1895 , providerId.GetPointer(), operationId.GetPointer());
1897 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1898 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1900 pStmt = CreateStatementN(db, query);
1901 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1903 pEnum = ExecuteStatementN(db, pStmt);
1906 if (pEnum->MoveNext() == E_SUCCESS)
1908 PackageId packageId;
1909 pEnum->GetStringAt(0, packageId);
1911 pPkgInfo = GetPackageInfoN(packageId);
1918 r = E_OBJ_NOT_FOUND;
1927 _PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
1929 result r = E_SUCCESS;
1931 DbStatement* pStmt = null;
1932 DbEnumerator* pEnum = null;
1935 PackageInfo* pPkgInfo = null;
1936 _PackageInfoImpl* pPackageInfoImpl = null;
1937 ArrayList* pList = null;
1939 pPkgInfo = GetPackageInfoN(packageId);
1940 SysTryCatch(NID_APP, pPkgInfo != null, , r, "[%s] GetPackageInfoN() is failed", GetErrorMessage(r));
1942 pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo);
1943 query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId());
1945 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1946 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1948 pStmt = CreateStatementN(db, query);
1949 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1950 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1952 pEnum = ExecuteStatementN(db, pStmt);
1956 pList = new (std::nothrow) ArrayList;
1957 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
1961 while (pEnum->MoveNext() == E_SUCCESS)
1963 _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl;
1964 SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null.");
1970 String mainmenuIcon;
1972 String quickpanelIcon;
1976 pEnum->GetIntAt(0, uniqueId);
1977 pEnum->GetIntAt(1, pkgId);
1978 pEnum->GetStringAt(2, name);
1979 pEnum->GetStringAt(3, defaultapp);
1980 pEnum->GetStringAt(4, mainmenuIcon);
1981 pEnum->GetStringAt(5, settingIcon);
1982 pEnum->GetStringAt(7, quickpanelIcon);
1983 pEnum->GetIntAt(9, appFeature);
1984 pEnum->GetStringAt(10, packageName);
1986 pPackageAppInfoImpl->SetUniqueId(uniqueId);
1987 pPackageAppInfoImpl->SetPkgId(pkgId);
1988 pPackageAppInfoImpl->SetName(name);
1989 pPackageAppInfoImpl->SetDefault(defaultapp);
1990 pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon);
1991 pPackageAppInfoImpl->SetSettingIcon(settingIcon);
1992 pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon);
1993 pPackageAppInfoImpl->SetAppFeature(appFeature);
1994 pPackageAppInfoImpl->SetPackageName(packageName);
1996 pList->Add(*pPackageAppInfoImpl);
2010 _PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const
2012 result r = E_SUCCESS;
2014 DbStatement* pStmt = null;
2015 DbEnumerator* pEnum = null;
2017 ArrayList* pList = null;
2019 query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
2021 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2022 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2024 pStmt = CreateStatementN(db, query);
2025 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2026 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2028 pEnum = ExecuteStatementN(db, pStmt);
2031 pList = new (std::nothrow) ArrayList;
2032 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
2036 while (pEnum->MoveNext() == E_SUCCESS)
2038 _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl;
2039 SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null.");
2044 pEnum->GetStringAt(1, name);
2045 pEnum->GetStringAt(2, value);
2047 pLaunchCondtion->SetName(name);
2048 pLaunchCondtion->SetValue(value);
2050 pList->Add(*pLaunchCondtion);
2052 SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer());
2064 _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pName, char* pPackageName, int bufferSize)
2066 result r = E_SUCCESS;
2068 DbStatement* pStmt = null;
2069 DbEnumerator* pEnum = null;
2071 Tizen::Base::String packageName;
2077 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2078 "True", packageId.GetPointer());
2084 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and APP_NAME = '%ls' and PkgInfo.PKG_ID = '%ls'",
2085 pName->GetPointer(), packageId.GetPointer());
2088 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2089 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2091 pStmt = CreateStatementN(db, query);
2092 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2093 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2095 pEnum = ExecuteStatementN(db, pStmt);
2098 if (pEnum->MoveNext() == E_SUCCESS)
2100 pEnum->GetStringAt(0, packageName);
2101 snprintf(pPackageName, bufferSize, "%ls", packageName.GetPointer());
2107 r = E_OBJ_NOT_FOUND;
2117 _PackageManagerImpl::GetDefaultAppExecutableName(const PackageId& packageId)
2119 result r = E_SUCCESS;
2121 DbStatement* pStmt = null;
2122 DbEnumerator* pEnum = null;
2124 String executableName;
2128 L"SELECT AppInfo.APP_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2129 "True", packageId.GetPointer());
2131 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2132 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2134 pStmt = CreateStatementN(db, query);
2135 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2136 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2138 pEnum = ExecuteStatementN(db, pStmt);
2141 if (pEnum->MoveNext() == E_SUCCESS)
2143 pEnum->GetStringAt(0, executableName);
2149 r = E_OBJ_NOT_FOUND;
2156 return executableName;
2160 _PackageManagerImpl::CreateStatementN(Database& db, const String& query)
2162 result r = E_SUCCESS;
2163 DbStatement* pStmt = null;
2165 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2167 pStmt = db.CreateStatementN(query);
2168 r = GetLastResult();
2170 if (r != E_OBJECT_LOCKED)
2176 SysLog(NID_APP, "RetryCount[%d] CreateStatementN - E_OBJECT_LOCKED", i);
2187 _PackageManagerImpl::ExecuteStatementN(Database& db, const DbStatement* pStmt)
2189 result r = E_SUCCESS;
2190 DbEnumerator* pEnum = null;
2192 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2194 pEnum = db.ExecuteStatementN(*pStmt);
2195 r = GetLastResult();
2197 if (r != E_OBJECT_LOCKED)
2203 SysLog(NID_APP, "RetryCount[%d] ExecuteStatementN - E_OBJECT_LOCKED", i);
2213 } } } // Tizen::App::Package