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 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. [Package = %ls]", pArg->__packageId.GetPointer());
79 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
83 SysLog(NID_APP, "Uninstallation is Completed. [Package = %ls]", pArg->__packageId.GetPointer());
84 pListener->OnPackageUninstallationCompleted(pArg->__packageId, true);
89 if (pArg->__install == false)
91 SysLog(NID_APP, "Uninstallation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
92 pListener->OnPackageUninstallationCompleted(pArg->__packageId, false);
96 else if (pArg->__eventKey == L"error")
100 if (pArg->__eventValue == L"62")
102 SysLog(NID_APP, "Installation is Completed(Error = STORAGE_FULL(62)). [Package = %ls]", pArg->__packageId.GetPointer());
103 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_STORAGE_FULL);
107 SysLog(NID_APP, "Installation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
108 pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
112 else if (pArg->__eventKey == L"install_percent")
114 std::unique_ptr<char[]> pProgress(_StringConverter::CopyToCharArrayN(pArg->__eventValue));
117 sscanf(pProgress.get(), "%d", &progress);
119 SysLog(NID_APP, "InstallationInProgress [%d]", progress);
120 pListener->OnPackageInstallationInProgress(pArg->__packageId, progress);
125 _PackageManagerImpl::GetPackageIdByAppId(const AppId& appId)
127 SysTryReturn(NID_APP, appId.IsEmpty() == false, L"", E_INVALID_ARG, "appId is empty");
131 char* pPackageId = null;
132 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
134 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
135 SysTryReturn(NID_APP, pAppId, L"", E_OUT_OF_MEMORY, "pAppId is null");
137 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
138 SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
140 result = pkgmgrinfo_appinfo_get_pkgname(pAppInfoHandle, &pPackageId);
142 packageId.Append(pPackageId);
146 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
149 SysLog(NID_APP, "app = [%ls], package = [%ls]", appId.GetPointer(), packageId.GetPointer());
155 _PackageManagerImpl::AddEventListener(IPackageInstallationEventListener* pListener, int priority)
157 SysTryReturnResult(NID_APP, (priority < 3) && (priority >= 0), E_INVALID_ARG, "priority is invalid.");
159 result r = E_SUCCESS;
162 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
163 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
165 while (pEnum->MoveNext() == E_SUCCESS)
167 _PackageManagerEvent* pEvent = null;
168 pEnum->GetCurrent(pEvent);
171 if (pEvent->__pListener == pListener)
173 SysLog(NID_APP, "The event listener already exist. listener = [0x%x]", pListener);
174 return E_OBJ_ALREADY_EXIST;
179 if (__pListeningClient == null)
181 __pListeningClient = pkgmgr_client_new(PC_LISTENING);
182 SysTryReturnResult(NID_APP, __pListeningClient != null, E_SYSTEM, "pkgmgr_client_new(PC_LISTENING) failed");
184 res = pkgmgr_client_listen_status(__pListeningClient, PackageEventHandler, this);
185 if (res < PKGMGR_R_OK)
187 pkgmgr_client_free(__pListeningClient);
188 __pListeningClient = null;
190 if (res == PKGMGR_R_EINVAL)
192 SysLog(NID_APP, "pkgmgr_client_listen_status() returns ARGV error");
193 return E_INVALID_ARG;
195 else if (res == PKGMGR_R_ECOMM)
197 SysLog(NID_APP, "pkgmgr_client_listen_status() returns COMM error");
199 else if (res == PKGMGR_R_ETIMEOUT)
201 SysLog(NID_APP, "pkgmgr_client_listen_status() returns TIME_OUT error");
203 else if (res == PKGMGR_R_ERROR)
205 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error");
209 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error, res = %d", res);
216 _PackageManagerEvent* pEvent = new (std::nothrow) _PackageManagerEvent();
217 SysTryReturnResult(NID_APP, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
219 r = pEvent->Construct();
220 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "pEvent->Construct() failed.");
222 pEvent->__pListener = pListener;
224 r = pEvent->AddListener(*pListener, true);
225 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "pEvent->AddListener() failed. [%s]", GetErrorMessage(r));
227 r = __packageEventListenerList.Add(pEvent);
228 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
230 SysLog(NID_APP, "Add PackageInstallationEventListener = [0x%x]", pListener);
235 _PackageManagerImpl::RemoveEventListener(IPackageInstallationEventListener* pListener)
237 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
238 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
240 result r = E_SUCCESS;
242 while (pEnum->MoveNext() == E_SUCCESS)
244 _PackageManagerEvent* pEvent = null;
245 pEnum->GetCurrent(pEvent);
248 if (pEvent->__pListener == pListener)
250 r = __packageEventListenerList.Remove(pEvent);
251 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
255 SysLog(NID_APP, "Remove PackageInstallationEventListener = [0x%x]", pListener);
261 return E_OBJ_NOT_FOUND;
265 _PackageManagerImpl::GetPackageInfoN(const PackageId& packageId) const
267 SysTryReturn(NID_APP, packageId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageId is empty.");
268 SysTryReturn(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, null, E_INVALID_ARG, "packageId is invalid.(length)");
270 result r = E_SUCCESS;
271 PackageInfo* pPackageInfo = null;
273 pPackageInfo = new (std::nothrow) PackageInfo;
274 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
276 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
277 r = pPackageInfoImpl->Construct(packageId);
278 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] package (%ls) is not found.", packageId.GetPointer());
288 _PackageManagerImpl::GetPackageAppInfoN(const AppId& appId) const
290 SysTryReturn(NID_APP, appId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
292 result r = E_SUCCESS;
293 PackageAppInfo* pPackageAppInfo = null;
295 pPackageAppInfo = new (std::nothrow) PackageAppInfo;
296 SysTryReturn(NID_APP, pPackageAppInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageAppInfo instance must not be null.");
298 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo);
299 r = pPackageAppInfoImpl->Construct(appId);
300 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] app (%ls) is not found.", appId.GetPointer());
302 return pPackageAppInfo;
305 delete pPackageAppInfo;
310 _PackageManagerImpl::GetPackageInfoListN(void) const
312 result r = E_SUCCESS;
314 ArrayList* pList = null;
316 pList = new (std::nothrow) ArrayList();
317 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
320 res = pkgmgrinfo_pkginfo_get_list(PackageInfoEventHandler, pList);
323 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_list() is failed. result = [%d]", res);
325 pList->RemoveAll(true);
334 _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
336 SysTryReturn(NID_APP, packageId.IsEmpty() == false, false, E_INVALID_ARG, "packageId is empty");
339 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
341 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
342 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
344 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
347 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
351 if(pPackageInfoHandle)
353 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
356 SysLog(NID_APP, "package = [%ls] is installed.", packageId.GetPointer());
362 _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& packagePath, IPackageInstallationResponseListener* pListener)
364 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
365 SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
366 SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
368 String extension = File::GetFileExtension(packagePath);
369 SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
371 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(packagePath));
372 SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null.");
374 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
375 SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null.");
377 if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
379 SysLog(NID_APP, "package = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
383 SysLog(NID_APP, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
387 // optionalData = 12345abcde
389 optionalData.Append(packageId);
391 std::unique_ptr<char[]> pOptionalData(_StringConverter::CopyToCharArrayN(optionalData));
392 SysTryReturnResult(NID_APP, pOptionalData, E_OUT_OF_MEMORY, "pOptionalData is null.");
394 SysLog(NID_APP, "optionalData = [%s]", pOptionalData.get());
396 result r = E_SUCCESS;
397 _PackageManagerProxy packageManagerProxy;
398 r = packageManagerProxy.Construct();
399 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
401 r = packageManagerProxy.InstallPackage(packageId, packagePath, null);
402 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.InstallPackage() failed.");
404 if (__pRequestClient == null)
406 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
407 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
410 int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), pOptionalData.get(), PM_QUIET, InstallationEventHandler, pListener);
412 if (res < PKGMGR_R_OK)
414 pkgmgr_client_free(__pRequestClient);
415 __pRequestClient = null;
417 if (res == PKGMGR_R_EINVAL)
419 SysLog(NID_APP, "pkgmgr_client_install() returns ARGV error");
420 return E_INVALID_ARG;
422 else if (res == PKGMGR_R_ECOMM)
424 SysLog(NID_APP, "pkgmgr_client_install() returns COMM error");
426 else if (res == PKGMGR_R_ETIMEOUT)
428 SysLog(NID_APP, "pkgmgr_client_install() returns TIME_OUT error");
430 else if (res == PKGMGR_R_ERROR)
432 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error");
436 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error, res = %d", res);
446 _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener)
448 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
449 SysTryReturnResult(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The packageId is invalid.(length)");
450 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
452 result r = E_SUCCESS;
455 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
457 _PackageManagerProxy packageManagerProxy;
458 r = packageManagerProxy.Construct();
459 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
461 r = packageManagerProxy.UninstallPackage(packageId, pListener);
462 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.UninstallPackage() failed.");
464 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
465 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
467 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
468 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
470 res = pkgmgrinfo_pkginfo_get_type(pPackageInfoHandle, &pType);
471 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
473 if (__pRequestClient == null)
475 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
476 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
479 res = pkgmgr_client_uninstall(__pRequestClient, pType, pPackageId.get(), PM_QUIET, UninstallationEventHandler, pListener);
480 SysLog(NID_APP, "pkgmgr_client_uninstall - req=[%d], package=[%s], type=[%s]", res, pPackageId.get(), pType);
482 if(pPackageInfoHandle)
484 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
487 if (res < PKGMGR_R_OK)
489 pkgmgr_client_free(__pRequestClient);
490 __pRequestClient = null;
492 if (res == PKGMGR_R_EINVAL)
494 SysLog(NID_APP, "pkgmgr_client_uninstall() returns ARGV error");
495 return E_INVALID_ARG;
497 else if (res == PKGMGR_R_ECOMM)
499 SysLog(NID_APP, "pkgmgr_client_uninstall() returns COMM error");
501 else if (res == PKGMGR_R_ETIMEOUT)
503 SysLog(NID_APP, "pkgmgr_client_uninstall() returns TIME_OUT error");
505 else if (res == PKGMGR_R_ERROR)
507 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error");
511 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error, res = %d", res);
521 _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId)
523 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
524 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
528 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
529 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
531 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
532 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
534 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
535 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
537 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
538 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
540 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
541 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
543 if (storage == PMINFO_EXTERNAL_STORAGE)
545 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
546 return E_INVALID_OPERATION;
549 if (__pRequestClient == null)
551 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
552 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
555 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, %s, %s)", pType, pPackageId.get());
556 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, __pRequestClient, pType, pPackageId.get(), null, null, null);
558 if (packageInfoHandle)
560 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
563 if (res < PKGMGR_R_OK)
565 pkgmgr_client_free(__pRequestClient);
566 __pRequestClient = null;
568 if (res == PKGMGR_R_EINVAL)
570 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
571 return E_INVALID_ARG;
573 else if (res == PKGMGR_R_ERROR)
575 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
579 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
589 _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
591 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
592 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
596 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
597 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
599 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
600 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
602 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
603 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
605 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
606 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
608 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
609 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
611 if (storage == PMINFO_INTERNAL_STORAGE)
613 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
614 return E_INVALID_OPERATION;
617 if (__pRequestClient == null)
619 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
620 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
623 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, %s, %s)", pType, pPackageId.get());
624 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, __pRequestClient, pType, pPackageId.get(), null, null, null);
626 if (packageInfoHandle)
628 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
631 if (res < PKGMGR_R_OK)
633 pkgmgr_client_free(__pRequestClient);
634 __pRequestClient = null;
636 if (res == PKGMGR_R_EINVAL)
638 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
639 return E_INVALID_ARG;
641 else if (res == PKGMGR_R_ERROR)
643 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
647 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
657 _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
659 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
663 IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData;
665 if (strcmp(pKey, "end") == 0)
667 if (strcmp(pVal, "ok") == 0)
669 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
670 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_SUCCESS)");
675 else if (strcmp(pKey, "error") == 0)
677 if (strcmp(pVal, "62") == 0)
679 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_STORAGE_FULL);
680 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_STORAGE_FULL)");
684 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
685 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE)");
688 else if (strcmp(pKey, "install_percent") == 0)
691 sscanf(pVal, "%d", &progress);
693 pListener->OnPackageInstallationInProgressResponseReceived(pPackageId, progress);
694 SysLog(NID_APP, "OnPackageInstallationInProgressResponseReceived(%s, %d)", pPackageId, progress);
702 _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
704 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
708 if (strcmp(pKey, "end") == 0)
710 IPackageUninstallationResponseListener* pListener = (IPackageUninstallationResponseListener*) pData;
712 if (strcmp(pVal, "ok") == 0)
714 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(true)");
715 pListener->OnPackageUninstallationResponseReceived(pPackageId, true);
719 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(false)");
720 pListener->OnPackageUninstallationResponseReceived(pPackageId, false);
731 _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
733 SysTryReturn(NID_APP, filePath.IsEmpty() == false, null, E_INVALID_ARG, "filePath is empty.");
734 SysTryReturn(NID_APP, File::IsFileExist(filePath) == true, null, E_FILE_NOT_FOUND, "package is not existed.");
736 String extension = File::GetFileExtension(filePath);
737 SysTryReturn(NID_APP, extension.IsEmpty() == false, null, E_INVALID_ARG, "extension is empty.");
739 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(filePath));
740 SysTryReturn(NID_APP, pPackagePath, null, E_OUT_OF_MEMORY, "pPackagePath is null.");
742 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
743 SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null.");
745 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
746 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
748 SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
752 if (strcasecmp(pExtension.get(), "tpk") == 0)
754 _PackageParser packageParser;
756 res = packageParser.Construct(pPackageInfo.get());
757 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
759 res = packageParser.Parse(filePath);
760 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
762 else if (strcasecmp(pExtension.get(), "wgt") == 0)
764 pkgmgr_info* pPkgmgrInfo = null;
766 pPkgmgrInfo = pkgmgr_client_check_pkginfo_from_file(pPackagePath.get());
767 SysTryReturn(NID_APP, pPkgmgrInfo, null, E_PARSING_FAILED, "pkgmgr_client_check_pkginfo_from_file(%s) is failed.", pPackagePath.get());
769 _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo;
770 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
772 SysLog(NID_APP, "package(%s), version(%s), label(%s), description(%s), author(%s), icon_size(%d), pkgname(%s)", pPkgInfo->pkgid, pPkgInfo->version, pPkgInfo->label,
773 pPkgInfo->pkg_description, pPkgInfo->author, pPkgInfo->icon_size, pPkgInfo->pkg_name);
775 pPackageInfoImpl->SetType(PACKAGE_TYPE_WGT);
776 pPackageInfoImpl->SetId(pPkgInfo->pkgid);
777 pPackageInfoImpl->SetVersion(pPkgInfo->version);
778 pPackageInfoImpl->SetDisplayName(pPkgInfo->label);
779 pPackageInfoImpl->SetDescription(pPkgInfo->pkg_description);
780 pPackageInfoImpl->SetAuthor(pPkgInfo->author);
781 pPackageInfoImpl->SetMainAppId(pPkgInfo->pkg_name);
783 if (IsHybridPackage(filePath) == true)
785 PackageInfo hybridServiceInfo;
786 _PackageParser packageParser;
788 res = packageParser.Construct(&hybridServiceInfo);
789 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
791 res = packageParser.Parse(filePath);
792 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
794 IList* pList = hybridServiceInfo.GetPrivilegeListN();
797 for (int i = 0; i < pList->GetCount(); i++)
799 PrivilegeInfo* pPrivilegeInfo = dynamic_cast < PrivilegeInfo* >(pList->GetAt(i));
802 String privilege = pPrivilegeInfo->GetId();
803 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(privilege));
804 SysLog(NID_APP, "privilege[%ls] is added for hybrid.", privilege.GetPointer());
810 if (pPkgInfo->privilege_list)
813 pList = g_list_first(pPkgInfo->privilege_list);
816 char* pPrivilege = (char*)pList->data;
819 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege));
822 pList = g_list_next(pList);
824 g_list_free(pPkgInfo->privilege_list);
827 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
830 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
832 pPackageAppInfoImpl->SetAppId(pPkgInfo->pkg_name);
833 pPackageAppInfoImpl->SetAppName(pPkgInfo->label);
834 pPackageAppInfoImpl->SetAppDisplayName(pPkgInfo->label);
835 pPackageAppInfoImpl->SetMainApp(true);
836 if ((pPkgInfo->icon_buf) && (pPkgInfo->icon_size > 0))
838 pPackageAppInfoImpl->SetAppMenuIconBuffer(pPkgInfo->icon_buf, pPkgInfo->icon_size);
841 pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release());
845 SysLog(NID_APP, "pPackageAppInfo instance must not be null.");
846 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
850 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
854 SysTryReturn(NID_APP, false, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
857 SetLastResult(E_SUCCESS);
858 return pPackageInfo.release();
862 _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
864 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
866 std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
867 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
869 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
870 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
874 int res = PMINFO_R_OK;
875 pkgmgrinfo_pkginfo_filter_h handle = null;
877 res = pkgmgrinfo_pkginfo_filter_create(&handle);
878 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
880 while(pEnum->MoveNext() == E_SUCCESS)
882 String* pKey = static_cast< String* >(pEnum->GetKey());
883 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
885 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
886 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
888 bool value = pVal->ToBool();
890 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
892 if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
894 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
895 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
897 else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
899 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
900 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
902 else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
904 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
905 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
907 else if ((*pKey) == PACKAGE_FILTER_TPK)
909 SysTryCatch(NID_APP, value == true, , E_SYSTEM, "Value(false) is invalid for PACKAGE_FILTER_TPK.");
911 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "tpk");
912 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(TYPE, tpk) is failed. [%d]", res);
914 else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
916 String installedStorage;
919 installedStorage = L"installed_external";
923 installedStorage = L"installed_internal";
926 std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
927 SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
929 SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
931 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
932 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
936 SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
940 res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList.get());
941 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed. [%d]", res);
946 pkgmgrinfo_pkginfo_filter_destroy(handle);
949 if (pList->GetCount() <= 0)
951 SysLog(NID_APP, "pList's count is 0.");
955 return pList.release();
959 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) const
961 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
963 std::unique_ptr< IMapEnumerator > pEnum(packageAppFilterMap.GetMapEnumeratorN());
964 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
966 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
967 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
972 bool definedKey = false;
973 bool metadataKey = false;
975 ArrayList metadataList;
977 pkgmgrinfo_appinfo_filter_h handle = null;
978 pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null;
980 res = pkgmgrinfo_appinfo_filter_create(&handle);
981 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res);
983 res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle);
984 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res);
986 while(pEnum->MoveNext() == E_SUCCESS)
988 String* pKey = static_cast< String* >(pEnum->GetKey());
989 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
991 if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE)
995 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
996 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
998 bool nodisplay = !(pVal->ToBool());
999 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), nodisplay);
1001 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, nodisplay);
1002 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(NODISPLAY, %d) is failed. [%d]", nodisplay, res);
1005 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_ONBOOT)
1009 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1010 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1012 bool value = pVal->ToBool();
1013 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1015 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, value);
1016 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(ONBOOT, %d) is failed. [%d]", value, res);
1018 else if ((*pKey) == PACKAGE_APP_FILTER_AUTO_RESTART)
1022 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1023 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1025 bool value = pVal->ToBool();
1026 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1028 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, value);
1029 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(AUTORESTART, %d) is failed. [%d]", value, res);
1032 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCHING_HISTORY_VISIBLE)
1036 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1037 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1039 bool value = pVal->ToBool();
1040 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1042 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, value);
1043 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(TASKMANAGE, %d) is failed. [%d]", value, res);
1045 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_CONDITION)
1049 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1050 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1052 bool value = pVal->ToBool();
1053 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1055 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, value);
1056 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(LAUNCHCONDITION, %d) is failed. [%d]", value, res);
1058 else if ((*pKey) == PACKAGE_APP_FILTER_CATEGORY_HOMEAPP || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_LOCKAPP
1059 || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_MENUAPP)
1063 std::unique_ptr<char[]> pDefinedKey(_StringConverter::CopyToCharArrayN(*pKey));
1064 SysTryCatch(NID_APP, pDefinedKey, , E_OUT_OF_MEMORY, "pDefinedKey is null.");
1066 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1067 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1069 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), pVal->ToBool());
1070 SysTryCatch(NID_APP, pVal->ToBool() == true, , E_INVALID_ARG, "Value(false) is not allowed.");
1072 res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pDefinedKey.get());
1073 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pDefinedKey.get(), res);
1079 String* pVal = static_cast< String* >(pEnum->GetValue());
1080 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1082 SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
1084 std::unique_ptr<char[]> pMetaKey(_StringConverter::CopyToCharArrayN(*pKey));
1085 SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null.");
1087 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
1088 SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
1090 if ((*pVal) == L"*")
1092 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), null);
1093 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, null) is failed. [%d]", pMetaKey.get(), res);
1097 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), pValue.get());
1098 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, %s) is failed. [%d]", pMetaKey.get(), pValue.get(), res);
1103 if ((definedKey == true) && (metadataKey == false))
1105 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList.get());
1106 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_foreach_appinfo() failed. [%d]", res);
1108 else if ((definedKey == false) && (metadataKey == true))
1110 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList.get());
1111 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_foreach() failed. [%d]", res);
1117 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list);
1118 if (res != PMINFO_R_OK)
1120 SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res);
1124 metadataList.Construct();
1126 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, &metadataList);
1127 if (res != PMINFO_R_OK)
1129 SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res);
1133 for (int i = 0; i < list.GetCount(); i++)
1135 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i));
1136 if (pPackageAppInfo)
1138 SysLog(NID_APP, "PackageAppFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1140 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1141 appIdList.Add(pAppId.release());
1145 for (int j = 0; j < metadataList.GetCount(); j++)
1147 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j));
1148 if (pPackageAppInfo)
1150 AppId appId = pPackageAppInfo->GetAppId();
1152 if (appIdList.Contains(appId) == true)
1154 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1156 std::unique_ptr< PackageAppInfo > pAppInfo(new (std::nothrow) PackageAppInfo);
1157 SysTryCatch(NID_APP, pAppInfo, , E_OUT_OF_MEMORY, "pAppInfo is null.");
1159 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
1160 pPackageAppInfoImpl->Construct(appId);
1162 pList->Add(pAppInfo.release());
1166 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1175 pkgmgrinfo_appinfo_filter_destroy(handle);
1180 pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle);
1183 if (pList->GetCount() <= 0)
1185 SysLog(NID_APP, "pList's count is 0.");
1189 return pList.release();
1193 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
1195 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap Count is invalid.");
1196 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap Count is invalid.");
1198 ArrayList appIdList;
1200 std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap));
1201 if (pPackageFilterList == null)
1203 SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null.");
1207 for (int i = 0; i < pPackageFilterList->GetCount(); i++)
1209 PackageInfo* pPackageInfo = dynamic_cast < PackageInfo* >(pPackageFilterList->GetAt(i));
1212 std::unique_ptr< IList > pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
1213 if (pPackageAppInfoList)
1215 for (int j = 0; j < pPackageAppInfoList->GetCount(); j++)
1217 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppInfoList->GetAt(j));
1218 if (pPackageAppInfo)
1220 SysLog(NID_APP, "PackageFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1222 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1223 appIdList.Add(pAppId.release());
1230 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList);
1231 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
1233 std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap));
1234 if (pAppFilterList == null)
1236 SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null.");
1240 for (int k = 0; k < pAppFilterList->GetCount(); k++)
1242 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k));
1243 if (pPackageAppInfo)
1245 AppId appId = pPackageAppInfo->GetAppId();
1246 SysLog(NID_APP, "AppFilter - App [%ls]", appId.GetPointer());
1248 if (appIdList.Contains(appId) == true)
1250 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1252 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1253 SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null.");
1255 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1256 pPackageAppInfoImpl->Construct(appId);
1258 pList->Add(pPackageAppInfo.release());
1262 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1267 if (pList->GetCount() <= 0)
1269 SysLog(NID_APP, "pList's count is 0.");
1273 return pList.release();
1277 _PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1279 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1280 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1282 result r = E_SUCCESS;
1283 int res = PMINFO_R_OK;
1284 char* pPackageId = null;
1285 ArrayList* pList = (ArrayList*)pUserData;
1287 res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
1288 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
1290 std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
1291 SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1293 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1294 r = pPackageInfoImpl->Construct(pPackageId);
1295 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
1297 pList->Add(*pPackageInfo.release());
1303 _PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1305 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1306 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1308 result r = E_SUCCESS;
1309 int res = PMINFO_R_OK;
1310 char* pAppId = null;
1311 ArrayList* pList = (ArrayList*)pUserData;
1313 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1314 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1316 SysLog(NID_APP, "app = [%s]", pAppId);
1318 std::unique_ptr<PackageAppInfo> pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1319 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1321 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1322 r = pPackageAppInfoImpl->Construct(pAppId);
1323 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1325 pList->Add(*pPackageAppInfo.release());
1331 _PackageManagerImpl::PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1333 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1334 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1336 result r = E_SUCCESS;
1337 int res = PMINFO_R_OK;
1338 char* pAppId = null;
1339 ArrayList* pList = (ArrayList*)pUserData;
1341 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1342 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1344 SysLog(NID_APP, "app = [%s]", pAppId);
1346 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1347 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1349 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1350 r = pPackageAppInfoImpl->Construct(pAppId);
1351 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1353 pList->Add(*pPackageAppInfo.release());
1359 _PackageManagerImpl::IsHybridPackage(const String& filePath) const
1361 SysTryReturn(NID_APP, filePath.IsEmpty() == false, false, E_INVALID_ARG, "filePath is empty.");
1364 FileUnzipper unzipper;
1367 result r = unzipper.Construct(filePath);
1368 SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.Construct() failed.");
1370 r = unzipper.GetEntry(L"info/manifest.xml", zipEntry);
1373 SysLog(NID_APP, "It's hybrid package. [%ls]", filePath.GetPointer());
1378 SysLog(NID_APP, "It's not hybrid package. [%ls]", filePath.GetPointer());
1382 SetLastResult(E_SUCCESS);
1386 _PackageManagerImpl*
1387 _PackageManagerImpl::GetInstance(void)
1389 return PackageManager::GetInstance()->__pPackageManagerImpl;
1393 _PackageManagerImpl::Construct(void)
1397 result r = __installationList.Construct();
1398 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
1403 _PackageManagerImpl::_PackageManagerImpl(void)
1404 :__pRequestClient(null),
1405 __pListeningClient(null)
1409 _PackageManagerImpl::~_PackageManagerImpl(void)
1414 _PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
1416 result r = E_SUCCESS;
1417 bool install = true;
1420 if (strcmp(pEventKey, "start") == 0)
1422 if ((strcmp(pEventValue, "install") == 0)
1423 || (strcmp(pEventValue, "update") == 0)
1424 ||(strcmp(pEventValue, "uninstall") == 0)
1425 ||(strcmp(pEventValue, "move") == 0))
1427 PackageId* pPackageId = new (std::nothrow) String(packageId);
1428 SysTryReturnVoidResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null.");
1430 String* pOperation = new (std::nothrow) String(pEventValue);
1431 SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation is null.");
1433 r = __installationList.Add(*pPackageId, *pOperation);
1438 SysLog(NID_APP, "Failed to add installation condition.");
1439 SetLastResult(E_SYSTEM);
1444 else if (strcmp(pEventKey, "end") == 0)
1446 String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
1447 SysTryReturnVoidResult(NID_APP, pOperation != null, E_SYSTEM, "pOperation is null.");
1449 if (pOperation->Equals("uninstall", true) == true)
1453 else if (pOperation->Equals("move", true) == true)
1458 r = __installationList.Remove(packageId, true);
1459 SysTryReturnVoidResult(NID_APP, !IsFailed(r), E_SYSTEM, "installationList.Remove(%ls) failed. (%s)", packageId.GetPointer(), GetErrorMessage(r));
1462 if ((strcmp(pEventValue, "move") == 0) || (move == true))
1464 SysLog(NID_APP, "Skip move event.");
1468 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
1469 SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
1471 while (pEnum->MoveNext() == E_SUCCESS)
1473 _PackageManagerEvent* pEvent = null;
1474 pEnum->GetCurrent(pEvent);
1477 _PackageManagerEventArg* pEventArg= new (std::nothrow) _PackageManagerEventArg();
1478 SysTryReturnVoidResult(NID_APP, pEventArg, E_OUT_OF_MEMORY, "The memory is insufficient.");
1480 String eventKey(pEventKey);
1481 String eventValue(pEventValue);
1483 pEventArg->__packageId = packageId;
1484 pEventArg->__eventKey = eventKey;
1485 pEventArg->__eventValue = eventValue;
1486 pEventArg->__install = install;
1488 r = pEvent->Fire(*pEventArg);
1491 SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r));
1494 SysLog(NID_APP, "Package = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install);
1498 SysLog(NID_APP, "pEvent is null.");
1504 _PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const
1506 SysTryReturn(NID_APP, packageName.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageName is empty.");
1508 result r = E_SUCCESS;
1510 DbStatement* pStmt = null;
1511 DbEnumerator* pEnum = null;
1513 PackageInfo *pPackageInfo = null;
1515 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());
1517 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1518 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1520 pStmt = CreateStatementN(db, query);
1522 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1524 pEnum = ExecuteStatementN(db, pStmt);
1527 if (pEnum->MoveNext() == E_SUCCESS)
1529 pPackageInfo = new (std::nothrow) PackageInfo;
1530 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
1532 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
1538 String appApiVersion;
1541 String appDescription;
1545 int appStorageType = 0;
1546 DateTime appInstallationTime;
1549 pEnum->GetStringAt(1, id);
1550 pEnum->GetStringAt(3, appVersion);
1551 pEnum->GetStringAt(4, appType);
1552 pEnum->GetStringAt(5, appMimeType);
1553 pEnum->GetStringAt(6, appApiVersion);
1554 pEnum->GetStringAt(7, appName);
1555 pEnum->GetStringAt(8, appVendor);
1556 pEnum->GetStringAt(9, appDescription);
1557 pEnum->GetStringAt(10, appUrl);
1558 pEnum->GetStringAt(11, appCid);
1559 pEnum->GetStringAt(16, appRootPath);
1560 pEnum->GetIntAt(17, appStorageType);
1561 pEnum->GetDateTimeAt(18, appInstallationTime);
1562 pEnum->GetStringAt(21, appIconPath);
1564 pPackageInfoImpl->SetAppId(id);
1565 pPackageInfoImpl->SetAppVersion(appVersion);
1566 pPackageInfoImpl->SetAppMimeType(appMimeType);
1567 pPackageInfoImpl->SetAppApiVersion(appApiVersion);
1568 pPackageInfoImpl->SetAppName(appName);
1569 pPackageInfoImpl->SetAppVendor(appVendor);
1570 pPackageInfoImpl->SetAppDescription(appDescription);
1571 pPackageInfoImpl->SetAppUrl(appUrl);
1572 pPackageInfoImpl->SetAppCid(appCid);
1573 pPackageInfoImpl->SetAppRootPath(appRootPath);
1574 pPackageInfoImpl->SetAppStorageType(appStorageType);
1575 pPackageInfoImpl->SetAppInstallationTime(appInstallationTime);
1576 pPackageInfoImpl->SetAppIconPath(appIconPath);
1583 r = E_OBJ_NOT_FOUND;
1588 return pPackageInfo;
1592 _PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1594 SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null.");
1596 result r = E_SUCCESS;
1598 char* pPackage = null;
1599 ArrayList* pList = (ArrayList*)pUserData;
1601 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
1602 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1604 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1606 result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage);
1609 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname(): package = [%s]", pPackage);
1613 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result);
1616 r = pPackageInfoImpl->Construct(pPackage);
1617 SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pPackageInfoImpl->Construct() failed.");
1619 r = pList->Add(*pPackageInfo.release());
1620 SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pList->Add() failed.");
1626 _PackageManagerImpl::GetFilteredAppIdListN(const String& feature, const String& value) const
1628 result r = E_SUCCESS;
1630 DbStatement* pStmt = null;
1631 DbEnumerator* pEnum = null;
1633 ArrayList* pList = null;
1635 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());
1637 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1638 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1640 pStmt = CreateStatementN(db, query);
1641 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1643 pEnum = ExecuteStatementN(db, pStmt);
1647 pList = new (std::nothrow) ArrayList();
1648 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1651 while (pEnum->MoveNext() == E_SUCCESS)
1653 String* pPackageName = new (std::nothrow) String;
1654 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1656 pEnum->GetStringAt(0, *pPackageName);
1658 pList->Add(*pPackageName);
1666 r = E_OBJ_NOT_FOUND;
1675 _PackageManagerImpl::GetDataControlInfoN(const String& providerId, const String& type) const
1677 result r = E_SUCCESS;
1679 DbStatement* pStmt = null;
1680 DbEnumerator* pEnum = null;
1682 ArrayList* pList = null;
1684 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());
1686 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1687 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1689 pStmt = CreateStatementN(db, query);
1690 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1692 pEnum = ExecuteStatementN(db, pStmt);
1696 pList = new (std::nothrow) ArrayList();
1697 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1700 while (pEnum->MoveNext() == E_SUCCESS)
1702 String* pPackageName = new (std::nothrow) String;
1703 SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null.");
1705 String* pAccess = new (std::nothrow) String;
1706 SysTryReturn(NID_APP, pAccess != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pAccess instance must not be null.");
1708 pEnum->GetStringAt(0, *pPackageName);
1709 pList->Add(*pPackageName);
1711 pEnum->GetStringAt(1, *pAccess);
1712 pList->Add(*pAccess);
1720 r = E_OBJ_NOT_FOUND;
1729 _PackageManagerImpl::GetUiThemeListN(const PackageId& packageId) const
1731 result r = E_SUCCESS;
1733 DbStatement* pStmt = null;
1734 DbEnumerator* pEnum = null;
1736 HashMap* pList = null;
1738 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')"
1739 , packageId.GetPointer());
1741 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1742 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1744 pStmt = CreateStatementN(db, query);
1745 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1747 pEnum = ExecuteStatementN(db, pStmt);
1751 pList = new (std::nothrow) HashMap();
1752 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
1755 while (pEnum->MoveNext() == E_SUCCESS)
1757 String* pName = new (std::nothrow) String;
1758 SysTryCatch(NID_APP, pName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pName instance must not be null.");
1760 String* pValue = new (std::nothrow) String;
1761 SysTryCatch(NID_APP, pValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pValue instance must not be null.");
1763 pEnum->GetStringAt(0, *pName);
1764 pEnum->GetStringAt(1, *pValue);
1766 pList->Add(*pName, *pValue);
1774 r = E_OBJ_NOT_FOUND;
1783 _PackageManagerImpl::IsAppInstalled(const AppId& appId)
1785 SysTryReturn(NID_APP, appId.IsEmpty() == false, false, E_INVALID_ARG, "appId is empty.");
1788 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
1790 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
1791 SysTryReturn(NID_APP, pAppId, false, E_OUT_OF_MEMORY, "pAppId is null.");
1793 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
1796 SysLog(NID_APP, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
1802 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
1805 SysLog(NID_APP, "app = [%ls] is installed.", appId.GetPointer());
1811 _PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name,
1812 const char* key, const char* val, const void* pmsg, void* data)
1814 SysLog(NID_APP, "PackageEventHandler - req: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type,
1815 pkg_name, key, val);
1817 PackageType type = PACKAGE_TYPE_TPK;
1818 PackageId packageId(pkg_name);
1820 if (strcmp(pkg_type, "tpk") == 0)
1822 type = PACKAGE_TYPE_TPK;
1824 else if (strcmp(pkg_type, "wgt") == 0)
1826 type = PACKAGE_TYPE_WGT;
1830 SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type);
1834 _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance();
1835 pThis->SendPackageEvent(type, packageId, key, val);
1841 _PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId)
1843 result r = E_SUCCESS;
1845 DbStatement* pStmt = null;
1846 DbEnumerator* pEnum = null;
1848 String* pAppId = null;
1850 query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID",
1851 providerId.GetPointer());
1853 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1854 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1856 pStmt = CreateStatementN(db, query);
1857 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1859 pEnum = ExecuteStatementN(db, pStmt);
1863 if (pEnum->MoveNext() == E_SUCCESS)
1865 pAppId = new (std::nothrow) String;
1866 SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
1868 pEnum->GetStringAt(0, *pAppId);
1880 _PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
1882 result r = E_SUCCESS;
1883 PackageInfo* pPkgInfo = null;
1885 DbStatement* pStmt = null;
1886 DbEnumerator* pEnum = null;
1889 query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
1890 "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
1891 "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
1892 "GROUP BY AppInfoID"
1893 , providerId.GetPointer(), operationId.GetPointer());
1895 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1896 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1898 pStmt = CreateStatementN(db, query);
1899 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1901 pEnum = ExecuteStatementN(db, pStmt);
1904 if (pEnum->MoveNext() == E_SUCCESS)
1906 PackageId packageId;
1907 pEnum->GetStringAt(0, packageId);
1909 pPkgInfo = GetPackageInfoN(packageId);
1916 r = E_OBJ_NOT_FOUND;
1925 _PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
1927 result r = E_SUCCESS;
1929 DbStatement* pStmt = null;
1930 DbEnumerator* pEnum = null;
1933 PackageInfo* pPkgInfo = null;
1934 _PackageInfoImpl* pPackageInfoImpl = null;
1935 ArrayList* pList = null;
1937 pPkgInfo = GetPackageInfoN(packageId);
1938 SysTryCatch(NID_APP, pPkgInfo != null, , r, "[%s] GetPackageInfoN() is failed", GetErrorMessage(r));
1940 pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo);
1941 query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId());
1943 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1944 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1946 pStmt = CreateStatementN(db, query);
1947 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1948 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1950 pEnum = ExecuteStatementN(db, pStmt);
1954 pList = new (std::nothrow) ArrayList;
1955 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
1959 while (pEnum->MoveNext() == E_SUCCESS)
1961 _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl;
1962 SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null.");
1968 String mainmenuIcon;
1970 String quickpanelIcon;
1974 pEnum->GetIntAt(0, uniqueId);
1975 pEnum->GetIntAt(1, pkgId);
1976 pEnum->GetStringAt(2, name);
1977 pEnum->GetStringAt(3, defaultapp);
1978 pEnum->GetStringAt(4, mainmenuIcon);
1979 pEnum->GetStringAt(5, settingIcon);
1980 pEnum->GetStringAt(7, quickpanelIcon);
1981 pEnum->GetIntAt(9, appFeature);
1982 pEnum->GetStringAt(10, packageName);
1984 pPackageAppInfoImpl->SetUniqueId(uniqueId);
1985 pPackageAppInfoImpl->SetPkgId(pkgId);
1986 pPackageAppInfoImpl->SetName(name);
1987 pPackageAppInfoImpl->SetDefault(defaultapp);
1988 pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon);
1989 pPackageAppInfoImpl->SetSettingIcon(settingIcon);
1990 pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon);
1991 pPackageAppInfoImpl->SetAppFeature(appFeature);
1992 pPackageAppInfoImpl->SetPackageName(packageName);
1994 pList->Add(*pPackageAppInfoImpl);
2008 _PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const
2010 result r = E_SUCCESS;
2012 DbStatement* pStmt = null;
2013 DbEnumerator* pEnum = null;
2015 ArrayList* pList = null;
2017 query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
2019 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2020 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2022 pStmt = CreateStatementN(db, query);
2023 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2024 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2026 pEnum = ExecuteStatementN(db, pStmt);
2029 pList = new (std::nothrow) ArrayList;
2030 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
2034 while (pEnum->MoveNext() == E_SUCCESS)
2036 _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl;
2037 SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null.");
2042 pEnum->GetStringAt(1, name);
2043 pEnum->GetStringAt(2, value);
2045 pLaunchCondtion->SetName(name);
2046 pLaunchCondtion->SetValue(value);
2048 pList->Add(*pLaunchCondtion);
2050 SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer());
2062 _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pName, char* pPackageName, int bufferSize)
2064 result r = E_SUCCESS;
2066 DbStatement* pStmt = null;
2067 DbEnumerator* pEnum = null;
2069 Tizen::Base::String packageName;
2075 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2076 "True", packageId.GetPointer());
2082 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and APP_NAME = '%ls' and PkgInfo.PKG_ID = '%ls'",
2083 pName->GetPointer(), packageId.GetPointer());
2086 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2087 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2089 pStmt = CreateStatementN(db, query);
2090 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2091 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2093 pEnum = ExecuteStatementN(db, pStmt);
2096 if (pEnum->MoveNext() == E_SUCCESS)
2098 pEnum->GetStringAt(0, packageName);
2099 snprintf(pPackageName, bufferSize, "%ls", packageName.GetPointer());
2105 r = E_OBJ_NOT_FOUND;
2115 _PackageManagerImpl::GetDefaultAppExecutableName(const PackageId& packageId)
2117 result r = E_SUCCESS;
2119 DbStatement* pStmt = null;
2120 DbEnumerator* pEnum = null;
2122 String executableName;
2126 L"SELECT AppInfo.APP_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2127 "True", packageId.GetPointer());
2129 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2130 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2132 pStmt = CreateStatementN(db, query);
2133 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2134 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2136 pEnum = ExecuteStatementN(db, pStmt);
2139 if (pEnum->MoveNext() == E_SUCCESS)
2141 pEnum->GetStringAt(0, executableName);
2147 r = E_OBJ_NOT_FOUND;
2154 return executableName;
2158 _PackageManagerImpl::CreateStatementN(Database& db, const String& query)
2160 result r = E_SUCCESS;
2161 DbStatement* pStmt = null;
2163 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2165 pStmt = db.CreateStatementN(query);
2166 r = GetLastResult();
2168 if (r != E_OBJECT_LOCKED)
2174 SysLog(NID_APP, "RetryCount[%d] CreateStatementN - E_OBJECT_LOCKED", i);
2185 _PackageManagerImpl::ExecuteStatementN(Database& db, const DbStatement* pStmt)
2187 result r = E_SUCCESS;
2188 DbEnumerator* pEnum = null;
2190 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2192 pEnum = db.ExecuteStatementN(*pStmt);
2193 r = GetLastResult();
2195 if (r != E_OBJECT_LOCKED)
2201 SysLog(NID_APP, "RetryCount[%d] ExecuteStatementN - E_OBJECT_LOCKED", i);
2211 } } } // Tizen::App::Package