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 if (appId.StartsWith(L".", 10) == true)
135 appId.SubString(0, 10, packageId);
140 char* pPackageId = null;
141 pkgmgrinfo_appinfo_h pAppInfoHandle = null;
143 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
144 SysTryReturn(NID_APP, pAppId, L"", E_OUT_OF_MEMORY, "pAppId is null");
146 result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
147 SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
149 result = pkgmgrinfo_appinfo_get_pkgname(pAppInfoHandle, &pPackageId);
151 packageId.Append(pPackageId);
155 pkgmgrinfo_appinfo_destroy_appinfo(pAppInfoHandle);
159 SysLog(NID_APP, "app = [%ls], package = [%ls]", appId.GetPointer(), packageId.GetPointer());
165 _PackageManagerImpl::AddEventListener(IPackageInstallationEventListener* pListener, int priority)
167 SysTryReturnResult(NID_APP, (priority < 3) && (priority >= 0), E_INVALID_ARG, "priority is invalid.");
169 result r = E_SUCCESS;
172 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
173 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
175 while (pEnum->MoveNext() == E_SUCCESS)
177 _PackageManagerEvent* pEvent = null;
178 pEnum->GetCurrent(pEvent);
181 if (pEvent->__pListener == pListener)
183 SysLog(NID_APP, "The event listener already exist. listener = [0x%x]", pListener);
184 return E_OBJ_ALREADY_EXIST;
189 if (__pListeningClient == null)
191 __pListeningClient = pkgmgr_client_new(PC_LISTENING);
192 SysTryReturnResult(NID_APP, __pListeningClient != null, E_SYSTEM, "pkgmgr_client_new(PC_LISTENING) failed");
194 res = pkgmgr_client_listen_status(__pListeningClient, PackageEventHandler, this);
195 if (res < PKGMGR_R_OK)
197 pkgmgr_client_free(__pListeningClient);
198 __pListeningClient = null;
200 if (res == PKGMGR_R_EINVAL)
202 SysLog(NID_APP, "pkgmgr_client_listen_status() returns ARGV error");
203 return E_INVALID_ARG;
205 else if (res == PKGMGR_R_ECOMM)
207 SysLog(NID_APP, "pkgmgr_client_listen_status() returns COMM error");
209 else if (res == PKGMGR_R_ETIMEOUT)
211 SysLog(NID_APP, "pkgmgr_client_listen_status() returns TIME_OUT error");
213 else if (res == PKGMGR_R_ERROR)
215 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error");
219 SysLog(NID_APP, "pkgmgr_client_listen_status() returns Unknown error, res = %d", res);
226 _PackageManagerEvent* pEvent = new (std::nothrow) _PackageManagerEvent();
227 SysTryReturnResult(NID_APP, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
229 r = pEvent->Construct();
230 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "pEvent->Construct() failed.");
232 pEvent->__pListener = pListener;
234 r = pEvent->AddListener(*pListener, true);
235 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "pEvent->AddListener() failed. [%s]", GetErrorMessage(r));
237 r = __packageEventListenerList.Add(pEvent);
238 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
240 SysLog(NID_APP, "Add PackageInstallationEventListener = [0x%x]", pListener);
245 _PackageManagerImpl::RemoveEventListener(IPackageInstallationEventListener* pListener)
247 std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
248 SysTryReturnResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
250 result r = E_SUCCESS;
252 while (pEnum->MoveNext() == E_SUCCESS)
254 _PackageManagerEvent* pEvent = null;
255 pEnum->GetCurrent(pEvent);
258 if (pEvent->__pListener == pListener)
260 r = __packageEventListenerList.Remove(pEvent);
261 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
265 SysLog(NID_APP, "Remove PackageInstallationEventListener = [0x%x]", pListener);
271 return E_OBJ_NOT_FOUND;
275 _PackageManagerImpl::GetPackageInfoN(const PackageId& packageId) const
277 SysTryReturn(NID_APP, packageId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageId is empty.");
278 SysTryReturn(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, null, E_INVALID_ARG, "packageId is invalid.(length)");
280 result r = E_SUCCESS;
281 PackageInfo* pPackageInfo = null;
283 pPackageInfo = new (std::nothrow) PackageInfo;
284 SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
286 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
287 r = pPackageInfoImpl->Construct(packageId);
288 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] package (%ls) is not found.", packageId.GetPointer());
298 _PackageManagerImpl::GetPackageAppInfoN(const AppId& appId) const
300 SysTryReturn(NID_APP, appId.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
302 result r = E_SUCCESS;
303 PackageAppInfo* pPackageAppInfo = null;
305 pPackageAppInfo = new (std::nothrow) PackageAppInfo;
306 SysTryReturn(NID_APP, pPackageAppInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageAppInfo instance must not be null.");
308 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo);
309 r = pPackageAppInfoImpl->Construct(appId);
310 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] app (%ls) is not found.", appId.GetPointer());
312 return pPackageAppInfo;
315 delete pPackageAppInfo;
320 _PackageManagerImpl::GetPackageInfoListN(void) const
322 result r = E_SUCCESS;
324 ArrayList* pList = null;
326 pList = new (std::nothrow) ArrayList();
327 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
330 res = pkgmgrinfo_pkginfo_get_list(PackageInfoEventHandler, pList);
333 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_list() is failed. result = [%d]", res);
335 pList->RemoveAll(true);
344 _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
346 SysTryReturn(NID_APP, packageId.IsEmpty() == false, false, E_INVALID_ARG, "packageId is empty");
349 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
351 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
352 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
354 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
357 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
361 if(pPackageInfoHandle)
363 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
366 SysLog(NID_APP, "package = [%ls] is installed.", packageId.GetPointer());
372 _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& packagePath, IPackageInstallationResponseListener* pListener)
374 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
375 SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
376 SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
378 String extension = File::GetFileExtension(packagePath);
379 SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
381 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(packagePath));
382 SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null.");
384 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
385 SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null.");
387 if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
389 SysLog(NID_APP, "package = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
393 SysLog(NID_APP, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
397 // optionalData = 12345abcde
399 optionalData.Append(packageId);
401 std::unique_ptr<char[]> pOptionalData(_StringConverter::CopyToCharArrayN(optionalData));
402 SysTryReturnResult(NID_APP, pOptionalData, E_OUT_OF_MEMORY, "pOptionalData is null.");
404 SysLog(NID_APP, "optionalData = [%s]", pOptionalData.get());
406 result r = E_SUCCESS;
407 _PackageManagerProxy packageManagerProxy;
408 r = packageManagerProxy.Construct();
409 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
411 r = packageManagerProxy.InstallPackage(packageId, packagePath, null);
412 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.InstallPackage() failed.");
414 if (__pRequestClient == null)
416 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
417 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
420 int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), pOptionalData.get(), PM_QUIET, InstallationEventHandler, pListener);
422 if (res < PKGMGR_R_OK)
424 pkgmgr_client_free(__pRequestClient);
425 __pRequestClient = null;
427 if (res == PKGMGR_R_EINVAL)
429 SysLog(NID_APP, "pkgmgr_client_install() returns ARGV error");
430 return E_INVALID_ARG;
432 else if (res == PKGMGR_R_ECOMM)
434 SysLog(NID_APP, "pkgmgr_client_install() returns COMM error");
436 else if (res == PKGMGR_R_ETIMEOUT)
438 SysLog(NID_APP, "pkgmgr_client_install() returns TIME_OUT error");
440 else if (res == PKGMGR_R_ERROR)
442 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error");
446 SysLog(NID_APP, "pkgmgr_client_install() returns Unknown error, res = %d", res);
456 _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener)
458 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
459 SysTryReturnResult(NID_APP, packageId.GetLength() < NATIVE_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The packageId is invalid.(length)");
460 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
462 result r = E_SUCCESS;
465 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
467 _PackageManagerProxy packageManagerProxy;
468 r = packageManagerProxy.Construct();
469 SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "packageManagerProxy.Construct() failed.");
471 r = packageManagerProxy.UninstallPackage(packageId, pListener);
472 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "packageManagerProxy.UninstallPackage() failed.");
474 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
475 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
477 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
478 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
480 res = pkgmgrinfo_pkginfo_get_type(pPackageInfoHandle, &pType);
481 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
483 if (__pRequestClient == null)
485 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
486 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
489 res = pkgmgr_client_uninstall(__pRequestClient, pType, pPackageId.get(), PM_QUIET, UninstallationEventHandler, pListener);
490 SysLog(NID_APP, "pkgmgr_client_uninstall - req=[%d], package=[%s], type=[%s]", res, pPackageId.get(), pType);
492 if(pPackageInfoHandle)
494 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
497 if (res < PKGMGR_R_OK)
499 pkgmgr_client_free(__pRequestClient);
500 __pRequestClient = null;
502 if (res == PKGMGR_R_EINVAL)
504 SysLog(NID_APP, "pkgmgr_client_uninstall() returns ARGV error");
505 return E_INVALID_ARG;
507 else if (res == PKGMGR_R_ECOMM)
509 SysLog(NID_APP, "pkgmgr_client_uninstall() returns COMM error");
511 else if (res == PKGMGR_R_ETIMEOUT)
513 SysLog(NID_APP, "pkgmgr_client_uninstall() returns TIME_OUT error");
515 else if (res == PKGMGR_R_ERROR)
517 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error");
521 SysLog(NID_APP, "pkgmgr_client_uninstall() returns Unknown error, res = %d", res);
531 _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId)
533 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
534 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
538 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
539 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
541 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
542 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
544 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
545 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
547 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
548 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
550 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
551 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
553 if (storage == PMINFO_EXTERNAL_STORAGE)
555 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
556 return E_INVALID_OPERATION;
559 if (__pRequestClient == null)
561 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
562 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
565 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, %s, %s)", pType, pPackageId.get());
566 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 1, __pRequestClient, pType, pPackageId.get(), null, null, null);
568 if (packageInfoHandle)
570 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
573 if (res < PKGMGR_R_OK)
575 pkgmgr_client_free(__pRequestClient);
576 __pRequestClient = null;
578 if (res == PKGMGR_R_EINVAL)
580 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
581 return E_INVALID_ARG;
583 else if (res == PKGMGR_R_ERROR)
585 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
589 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
599 _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
601 SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty");
602 SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed.");
606 pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE;
607 pkgmgrinfo_pkginfo_h packageInfoHandle = null;
609 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
610 SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
612 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
613 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
615 res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
616 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
618 res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
619 SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
621 if (storage == PMINFO_INTERNAL_STORAGE)
623 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_installed_storage(): storage = [%d][E_INVALID_OPERATION]", storage);
624 return E_INVALID_OPERATION;
627 if (__pRequestClient == null)
629 __pRequestClient = pkgmgr_client_new(PC_REQUEST);
630 SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
633 SysLog(NID_APP, "pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, %s, %s)", pType, pPackageId.get());
634 res = pkgmgr_client_request_service(PM_REQUEST_MOVE, 0, __pRequestClient, pType, pPackageId.get(), null, null, null);
636 if (packageInfoHandle)
638 pkgmgrinfo_pkginfo_destroy_pkginfo(packageInfoHandle);
641 if (res < PKGMGR_R_OK)
643 pkgmgr_client_free(__pRequestClient);
644 __pRequestClient = null;
646 if (res == PKGMGR_R_EINVAL)
648 SysLog(NID_APP, "pkgmgr_client_move() returns ARGV error");
649 return E_INVALID_ARG;
651 else if (res == PKGMGR_R_ERROR)
653 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error");
657 SysLog(NID_APP, "pkgmgr_client_move() returns Unknown error, res = %d", res);
667 _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
669 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
673 IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData;
675 if (strcmp(pKey, "end") == 0)
677 if (strcmp(pVal, "ok") == 0)
679 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
680 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_SUCCESS)");
685 else if (strcmp(pKey, "error") == 0)
687 if (strcmp(pVal, "62") == 0)
689 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_STORAGE_FULL);
690 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_STORAGE_FULL)");
694 pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
695 SysLog(NID_APP, "OnPackageInstallationResponseReceived(PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE)");
698 else if (strcmp(pKey, "install_percent") == 0)
701 sscanf(pVal, "%d", &progress);
703 pListener->OnPackageInstallationInProgressResponseReceived(pPackageId, progress);
704 SysLog(NID_APP, "OnPackageInstallationInProgressResponseReceived(%s, %d)", pPackageId, progress);
712 _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
714 SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
718 if (strcmp(pKey, "end") == 0)
720 IPackageUninstallationResponseListener* pListener = (IPackageUninstallationResponseListener*) pData;
722 if (strcmp(pVal, "ok") == 0)
724 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(true)");
725 pListener->OnPackageUninstallationResponseReceived(pPackageId, true);
729 SysLog(NID_APP, "OnPackageUninstallationResponseReceived(false)");
730 pListener->OnPackageUninstallationResponseReceived(pPackageId, false);
741 _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
743 SysTryReturn(NID_APP, filePath.IsEmpty() == false, null, E_INVALID_ARG, "filePath is empty.");
744 SysTryReturn(NID_APP, File::IsFileExist(filePath) == true, null, E_FILE_NOT_FOUND, "package is not existed.");
746 String extension = File::GetFileExtension(filePath);
747 SysTryReturn(NID_APP, extension.IsEmpty() == false, null, E_INVALID_ARG, "extension is empty.");
749 std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(filePath));
750 SysTryReturn(NID_APP, pPackagePath, null, E_OUT_OF_MEMORY, "pPackagePath is null.");
752 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
753 SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null.");
755 std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
756 SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
758 SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
762 if (strcasecmp(pExtension.get(), "tpk") == 0)
764 _PackageParser packageParser;
766 res = packageParser.Construct(pPackageInfo.get());
767 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
769 res = packageParser.Parse(filePath);
770 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
772 else if (strcasecmp(pExtension.get(), "wgt") == 0)
774 pkgmgr_info* pPkgmgrInfo = null;
776 pPkgmgrInfo = pkgmgr_client_check_pkginfo_from_file(pPackagePath.get());
777 SysTryReturn(NID_APP, pPkgmgrInfo, null, E_PARSING_FAILED, "pkgmgr_client_check_pkginfo_from_file(%s) is failed.", pPackagePath.get());
779 _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo;
780 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
782 SysLog(NID_APP, "package(%s), version(%s), label(%s), description(%s), author(%s), icon_size(%d), pkgname(%s)", pPkgInfo->pkgid, pPkgInfo->version, pPkgInfo->label,
783 pPkgInfo->pkg_description, pPkgInfo->author, pPkgInfo->icon_size, pPkgInfo->pkg_name);
785 pPackageInfoImpl->SetType(PACKAGE_TYPE_WGT);
786 pPackageInfoImpl->SetId(pPkgInfo->pkgid);
787 pPackageInfoImpl->SetVersion(pPkgInfo->version);
788 pPackageInfoImpl->SetDisplayName(pPkgInfo->label);
789 pPackageInfoImpl->SetDescription(pPkgInfo->pkg_description);
790 pPackageInfoImpl->SetAuthor(pPkgInfo->author);
791 pPackageInfoImpl->SetMainAppId(pPkgInfo->pkg_name);
793 if (IsHybridPackage(filePath) == true)
795 PackageInfo hybridServiceInfo;
796 _PackageParser packageParser;
798 res = packageParser.Construct(&hybridServiceInfo);
799 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
801 res = packageParser.Parse(filePath);
802 SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
804 IList* pList = hybridServiceInfo.GetPrivilegeListN();
807 for (int i = 0; i < pList->GetCount(); i++)
809 PrivilegeInfo* pPrivilegeInfo = dynamic_cast < PrivilegeInfo* >(pList->GetAt(i));
812 String privilege = pPrivilegeInfo->GetId();
813 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(privilege));
814 SysLog(NID_APP, "privilege[%ls] is added for hybrid.", privilege.GetPointer());
820 if (pPkgInfo->privilege_list)
823 pList = g_list_first(pPkgInfo->privilege_list);
826 char* pPrivilege = (char*)pList->data;
829 pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege));
832 pList = g_list_next(pList);
834 g_list_free(pPkgInfo->privilege_list);
837 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
840 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
842 pPackageAppInfoImpl->SetAppId(pPkgInfo->pkg_name);
843 pPackageAppInfoImpl->SetAppName(pPkgInfo->label);
844 pPackageAppInfoImpl->SetAppDisplayName(pPkgInfo->label);
845 pPackageAppInfoImpl->SetMainApp(true);
846 if ((pPkgInfo->icon_buf) && (pPkgInfo->icon_size > 0))
848 pPackageAppInfoImpl->SetAppMenuIconBuffer(pPkgInfo->icon_buf, pPkgInfo->icon_size);
851 pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release());
855 SysLog(NID_APP, "pPackageAppInfo instance must not be null.");
856 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
860 pkgmgr_client_free_pkginfo(pPkgmgrInfo);
864 SysTryReturn(NID_APP, false, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
867 SetLastResult(E_SUCCESS);
868 return pPackageInfo.release();
872 _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
874 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
876 std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
877 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
879 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
880 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
884 int res = PMINFO_R_OK;
885 pkgmgrinfo_pkginfo_filter_h handle = null;
887 res = pkgmgrinfo_pkginfo_filter_create(&handle);
888 SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
890 while(pEnum->MoveNext() == E_SUCCESS)
892 String* pKey = static_cast< String* >(pEnum->GetKey());
893 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
895 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
896 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
898 bool value = pVal->ToBool();
900 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
902 if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
904 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
905 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
907 else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
909 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
910 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
912 else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
914 res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
915 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
917 else if ((*pKey) == PACKAGE_FILTER_TPK)
919 SysTryCatch(NID_APP, value == true, , E_SYSTEM, "Value(false) is invalid for PACKAGE_FILTER_TPK.");
921 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "tpk");
922 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(TYPE, tpk) is failed. [%d]", res);
924 else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
926 String installedStorage;
929 installedStorage = L"installed_external";
933 installedStorage = L"installed_internal";
936 std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
937 SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
939 SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
941 res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
942 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
946 SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
950 res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList.get());
951 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed. [%d]", res);
956 pkgmgrinfo_pkginfo_filter_destroy(handle);
959 if (pList->GetCount() <= 0)
961 SysLog(NID_APP, "pList's count is 0.");
965 return pList.release();
969 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) const
971 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
973 std::unique_ptr< IMapEnumerator > pEnum(packageAppFilterMap.GetMapEnumeratorN());
974 SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
976 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
977 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
982 bool definedKey = false;
983 bool metadataKey = false;
985 ArrayList metadataList;
987 pkgmgrinfo_appinfo_filter_h handle = null;
988 pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null;
990 res = pkgmgrinfo_appinfo_filter_create(&handle);
991 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res);
993 res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle);
994 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res);
996 while(pEnum->MoveNext() == E_SUCCESS)
998 String* pKey = static_cast< String* >(pEnum->GetKey());
999 SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
1001 if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE)
1005 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1006 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1008 bool nodisplay = !(pVal->ToBool());
1009 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), nodisplay);
1011 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, nodisplay);
1012 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(NODISPLAY, %d) is failed. [%d]", nodisplay, res);
1015 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_ONBOOT)
1019 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1020 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1022 bool value = pVal->ToBool();
1023 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1025 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, value);
1026 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(ONBOOT, %d) is failed. [%d]", value, res);
1028 else if ((*pKey) == PACKAGE_APP_FILTER_AUTO_RESTART)
1032 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1033 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1035 bool value = pVal->ToBool();
1036 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1038 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, value);
1039 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(AUTORESTART, %d) is failed. [%d]", value, res);
1042 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCHING_HISTORY_VISIBLE)
1046 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1047 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1049 bool value = pVal->ToBool();
1050 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1052 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, value);
1053 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(TASKMANAGE, %d) is failed. [%d]", value, res);
1055 else if ((*pKey) == PACKAGE_APP_FILTER_LAUNCH_CONDITION)
1059 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1060 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1062 bool value = pVal->ToBool();
1063 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
1065 res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, value);
1066 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(LAUNCHCONDITION, %d) is failed. [%d]", value, res);
1068 else if ((*pKey) == PACKAGE_APP_FILTER_CATEGORY_HOMEAPP || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_LOCKAPP
1069 || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_MENUAPP)
1073 std::unique_ptr<char[]> pDefinedKey(_StringConverter::CopyToCharArrayN(*pKey));
1074 SysTryCatch(NID_APP, pDefinedKey, , E_OUT_OF_MEMORY, "pDefinedKey is null.");
1076 Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
1077 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1079 SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), pVal->ToBool());
1080 SysTryCatch(NID_APP, pVal->ToBool() == true, , E_INVALID_ARG, "Value(false) is not allowed.");
1082 res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pDefinedKey.get());
1083 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pDefinedKey.get(), res);
1089 String* pVal = static_cast< String* >(pEnum->GetValue());
1090 SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
1092 SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
1094 std::unique_ptr<char[]> pMetaKey(_StringConverter::CopyToCharArrayN(*pKey));
1095 SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null.");
1097 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
1098 SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
1100 if ((*pVal) == L"*")
1102 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), null);
1103 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, null) is failed. [%d]", pMetaKey.get(), res);
1107 res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), pValue.get());
1108 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, %s) is failed. [%d]", pMetaKey.get(), pValue.get(), res);
1113 if ((definedKey == true) && (metadataKey == false))
1115 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList.get());
1116 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_foreach_appinfo() failed. [%d]", res);
1118 else if ((definedKey == false) && (metadataKey == true))
1120 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList.get());
1121 SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_foreach() failed. [%d]", res);
1127 res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list);
1128 if (res != PMINFO_R_OK)
1130 SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res);
1134 metadataList.Construct();
1136 res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, &metadataList);
1137 if (res != PMINFO_R_OK)
1139 SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res);
1143 for (int i = 0; i < list.GetCount(); i++)
1145 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i));
1146 if (pPackageAppInfo)
1148 SysLog(NID_APP, "PackageAppFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1150 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1151 appIdList.Add(pAppId.release());
1155 for (int j = 0; j < metadataList.GetCount(); j++)
1157 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j));
1158 if (pPackageAppInfo)
1160 AppId appId = pPackageAppInfo->GetAppId();
1162 if (appIdList.Contains(appId) == true)
1164 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1166 std::unique_ptr< PackageAppInfo > pAppInfo(new (std::nothrow) PackageAppInfo);
1167 SysTryCatch(NID_APP, pAppInfo, , E_OUT_OF_MEMORY, "pAppInfo is null.");
1169 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
1170 pPackageAppInfoImpl->Construct(appId);
1172 pList->Add(pAppInfo.release());
1176 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1185 pkgmgrinfo_appinfo_filter_destroy(handle);
1190 pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle);
1193 if (pList->GetCount() <= 0)
1195 SysLog(NID_APP, "pList's count is 0.");
1199 return pList.release();
1203 _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
1205 SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap Count is invalid.");
1206 SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap Count is invalid.");
1208 ArrayList appIdList;
1210 std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap));
1211 if (pPackageFilterList == null)
1213 SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null.");
1217 for (int i = 0; i < pPackageFilterList->GetCount(); i++)
1219 PackageInfo* pPackageInfo = dynamic_cast < PackageInfo* >(pPackageFilterList->GetAt(i));
1222 std::unique_ptr< IList > pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
1223 if (pPackageAppInfoList)
1225 for (int j = 0; j < pPackageAppInfoList->GetCount(); j++)
1227 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppInfoList->GetAt(j));
1228 if (pPackageAppInfo)
1230 SysLog(NID_APP, "PackageFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
1232 std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
1233 appIdList.Add(pAppId.release());
1240 std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList);
1241 SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
1243 std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap));
1244 if (pAppFilterList == null)
1246 SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null.");
1250 for (int k = 0; k < pAppFilterList->GetCount(); k++)
1252 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k));
1253 if (pPackageAppInfo)
1255 AppId appId = pPackageAppInfo->GetAppId();
1256 SysLog(NID_APP, "AppFilter - App [%ls]", appId.GetPointer());
1258 if (appIdList.Contains(appId) == true)
1260 SysLog(NID_APP, "App [%ls] is matched.", appId.GetPointer());
1262 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1263 SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null.");
1265 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1266 pPackageAppInfoImpl->Construct(appId);
1268 pList->Add(pPackageAppInfo.release());
1272 SysLog(NID_APP, "App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
1277 if (pList->GetCount() <= 0)
1279 SysLog(NID_APP, "pList's count is 0.");
1283 return pList.release();
1287 _PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
1289 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1290 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1292 result r = E_SUCCESS;
1293 int res = PMINFO_R_OK;
1294 char* pPackageId = null;
1295 ArrayList* pList = (ArrayList*)pUserData;
1297 res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
1298 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
1300 std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
1301 SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
1303 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1304 r = pPackageInfoImpl->Construct(pPackageId);
1305 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
1307 pList->Add(*pPackageInfo.release());
1313 _PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1315 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1316 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1318 result r = E_SUCCESS;
1319 int res = PMINFO_R_OK;
1320 char* pAppId = null;
1321 ArrayList* pList = (ArrayList*)pUserData;
1323 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1324 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1326 SysLog(NID_APP, "app = [%s]", pAppId);
1328 std::unique_ptr<PackageAppInfo> pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1329 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1331 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1332 r = pPackageAppInfoImpl->Construct(pAppId);
1333 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1335 pList->Add(*pPackageAppInfo.release());
1341 _PackageManagerImpl::PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
1343 SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
1344 SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
1346 result r = E_SUCCESS;
1347 int res = PMINFO_R_OK;
1348 char* pAppId = null;
1349 ArrayList* pList = (ArrayList*)pUserData;
1351 res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
1352 SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
1354 SysLog(NID_APP, "app = [%s]", pAppId);
1356 std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
1357 SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
1359 _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
1360 r = pPackageAppInfoImpl->Construct(pAppId);
1361 SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
1363 pList->Add(*pPackageAppInfo.release());
1369 _PackageManagerImpl::IsHybridPackage(const String& filePath) const
1371 SysTryReturn(NID_APP, filePath.IsEmpty() == false, false, E_INVALID_ARG, "filePath is empty.");
1374 FileUnzipper unzipper;
1377 result r = unzipper.Construct(filePath);
1378 SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.Construct() failed.");
1380 r = unzipper.GetEntry(L"info/manifest.xml", zipEntry);
1383 SysLog(NID_APP, "It's hybrid package. [%ls]", filePath.GetPointer());
1388 SysLog(NID_APP, "It's not hybrid package. [%ls]", filePath.GetPointer());
1392 SetLastResult(E_SUCCESS);
1396 _PackageManagerImpl*
1397 _PackageManagerImpl::GetInstance(void)
1399 return PackageManager::GetInstance()->__pPackageManagerImpl;
1403 _PackageManagerImpl::Construct(void)
1407 result r = __installationList.Construct();
1408 SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
1413 _PackageManagerImpl::_PackageManagerImpl(void)
1414 :__pRequestClient(null),
1415 __pListeningClient(null)
1419 _PackageManagerImpl::~_PackageManagerImpl(void)
1424 _PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
1426 result r = E_SUCCESS;
1427 bool install = true;
1429 if (strcmp(pEventKey, "start") == 0)
1431 if ((strcmp(pEventValue, "install") == 0)
1432 || (strcmp(pEventValue, "update") == 0)
1433 ||(strcmp(pEventValue, "uninstall") == 0))
1435 String* pAppId = new (std::nothrow) String(packageId);
1436 SysTryReturnVoidResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId instance must not be null.");
1438 String* pOperation = new (std::nothrow) String(pEventValue);
1439 SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null.");
1441 r = __installationList.Add(*pAppId, *pOperation);
1446 SysLog(NID_APP, "Failed to add installation condition.");
1447 SetLastResult(E_SYSTEM);
1452 else if (strcmp(pEventKey, "end") == 0)
1454 String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
1457 if (pOperation->Equals("uninstall", true) == true)
1462 r = __installationList.Remove(packageId, true);
1465 SysLogException(NID_APP, r, "[%s] Remove Element [%ls] is failed from installing list.", GetErrorMessage(r), packageId.GetPointer());
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 if (appId == _AppInfo::GetPackageId())
1793 pkgmgrinfo_pkginfo_h pPackageInfoHandle = null;
1795 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(appId));
1796 SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
1798 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
1799 SysTryReturn(NID_APP, result == 0, false, E_APP_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
1801 if(pPackageInfoHandle)
1803 pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
1810 _PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name,
1811 const char* key, const char* val, const void* pmsg, void* data)
1813 SysLog(NID_APP, "PackageEventHandler - req: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type,
1814 pkg_name, key, val);
1816 PackageType type = PACKAGE_TYPE_TPK;
1817 PackageId packageId(pkg_name);
1819 if (strcmp(pkg_type, "tpk") == 0)
1821 type = PACKAGE_TYPE_TPK;
1823 else if (strcmp(pkg_type, "wgt") == 0)
1825 type = PACKAGE_TYPE_WGT;
1829 SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type);
1833 _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance();
1834 pThis->SendPackageEvent(type, packageId, key, val);
1840 _PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId)
1842 result r = E_SUCCESS;
1844 DbStatement* pStmt = null;
1845 DbEnumerator* pEnum = null;
1847 String* pAppId = null;
1849 query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID",
1850 providerId.GetPointer());
1852 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1853 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1855 pStmt = CreateStatementN(db, query);
1856 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1858 pEnum = ExecuteStatementN(db, pStmt);
1862 if (pEnum->MoveNext() == E_SUCCESS)
1864 pAppId = new (std::nothrow) String;
1865 SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory");
1867 pEnum->GetStringAt(0, *pAppId);
1879 _PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
1881 result r = E_SUCCESS;
1882 PackageInfo* pPkgInfo = null;
1884 DbStatement* pStmt = null;
1885 DbEnumerator* pEnum = null;
1888 query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
1889 "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
1890 "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
1891 "GROUP BY AppInfoID"
1892 , providerId.GetPointer(), operationId.GetPointer());
1894 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1895 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1897 pStmt = CreateStatementN(db, query);
1898 SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1900 pEnum = ExecuteStatementN(db, pStmt);
1903 if (pEnum->MoveNext() == E_SUCCESS)
1905 PackageId packageId;
1906 pEnum->GetStringAt(0, packageId);
1908 pPkgInfo = GetPackageInfoN(packageId);
1915 r = E_OBJ_NOT_FOUND;
1924 _PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
1926 result r = E_SUCCESS;
1928 DbStatement* pStmt = null;
1929 DbEnumerator* pEnum = null;
1932 PackageInfo* pPkgInfo = null;
1933 _PackageInfoImpl* pPackageInfoImpl = null;
1934 ArrayList* pList = null;
1936 pPkgInfo = GetPackageInfoN(packageId);
1937 SysTryCatch(NID_APP, pPkgInfo != null, , r, "[%s] GetPackageInfoN() is failed", GetErrorMessage(r));
1939 pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo);
1940 query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId());
1942 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
1943 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
1945 pStmt = CreateStatementN(db, query);
1946 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
1947 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
1949 pEnum = ExecuteStatementN(db, pStmt);
1953 pList = new (std::nothrow) ArrayList;
1954 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
1958 while (pEnum->MoveNext() == E_SUCCESS)
1960 _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl;
1961 SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null.");
1967 String mainmenuIcon;
1969 String quickpanelIcon;
1973 pEnum->GetIntAt(0, uniqueId);
1974 pEnum->GetIntAt(1, pkgId);
1975 pEnum->GetStringAt(2, name);
1976 pEnum->GetStringAt(3, defaultapp);
1977 pEnum->GetStringAt(4, mainmenuIcon);
1978 pEnum->GetStringAt(5, settingIcon);
1979 pEnum->GetStringAt(7, quickpanelIcon);
1980 pEnum->GetIntAt(9, appFeature);
1981 pEnum->GetStringAt(10, packageName);
1983 pPackageAppInfoImpl->SetUniqueId(uniqueId);
1984 pPackageAppInfoImpl->SetPkgId(pkgId);
1985 pPackageAppInfoImpl->SetName(name);
1986 pPackageAppInfoImpl->SetDefault(defaultapp);
1987 pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon);
1988 pPackageAppInfoImpl->SetSettingIcon(settingIcon);
1989 pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon);
1990 pPackageAppInfoImpl->SetAppFeature(appFeature);
1991 pPackageAppInfoImpl->SetPackageName(packageName);
1993 pList->Add(*pPackageAppInfoImpl);
2007 _PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const
2009 result r = E_SUCCESS;
2011 DbStatement* pStmt = null;
2012 DbEnumerator* pEnum = null;
2014 ArrayList* pList = null;
2016 query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
2018 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2019 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2021 pStmt = CreateStatementN(db, query);
2022 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2023 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2025 pEnum = ExecuteStatementN(db, pStmt);
2028 pList = new (std::nothrow) ArrayList;
2029 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure.");
2033 while (pEnum->MoveNext() == E_SUCCESS)
2035 _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl;
2036 SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null.");
2041 pEnum->GetStringAt(1, name);
2042 pEnum->GetStringAt(2, value);
2044 pLaunchCondtion->SetName(name);
2045 pLaunchCondtion->SetValue(value);
2047 pList->Add(*pLaunchCondtion);
2049 SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer());
2061 _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pName, char* pPackageName, int bufferSize)
2063 result r = E_SUCCESS;
2065 DbStatement* pStmt = null;
2066 DbEnumerator* pEnum = null;
2068 Tizen::Base::String packageName;
2074 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2075 "True", packageId.GetPointer());
2081 L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and APP_NAME = '%ls' and PkgInfo.PKG_ID = '%ls'",
2082 pName->GetPointer(), packageId.GetPointer());
2085 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2086 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2088 pStmt = CreateStatementN(db, query);
2089 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2090 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2092 pEnum = ExecuteStatementN(db, pStmt);
2095 if (pEnum->MoveNext() == E_SUCCESS)
2097 pEnum->GetStringAt(0, packageName);
2098 snprintf(pPackageName, bufferSize, "%ls", packageName.GetPointer());
2104 r = E_OBJ_NOT_FOUND;
2114 _PackageManagerImpl::GetDefaultAppExecutableName(const PackageId& packageId)
2116 result r = E_SUCCESS;
2118 DbStatement* pStmt = null;
2119 DbEnumerator* pEnum = null;
2121 String executableName;
2125 L"SELECT AppInfo.APP_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'",
2126 "True", packageId.GetPointer());
2128 r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
2129 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
2131 pStmt = CreateStatementN(db, query);
2132 SysTryCatch(NID_APP, pStmt != null, GetLastResult(),
2133 GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
2135 pEnum = ExecuteStatementN(db, pStmt);
2138 if (pEnum->MoveNext() == E_SUCCESS)
2140 pEnum->GetStringAt(0, executableName);
2146 r = E_OBJ_NOT_FOUND;
2153 return executableName;
2157 _PackageManagerImpl::CreateStatementN(Database& db, const String& query)
2159 result r = E_SUCCESS;
2160 DbStatement* pStmt = null;
2162 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2164 pStmt = db.CreateStatementN(query);
2165 r = GetLastResult();
2167 if (r != E_OBJECT_LOCKED)
2173 SysLog(NID_APP, "RetryCount[%d] CreateStatementN - E_OBJECT_LOCKED", i);
2184 _PackageManagerImpl::ExecuteStatementN(Database& db, const DbStatement* pStmt)
2186 result r = E_SUCCESS;
2187 DbEnumerator* pEnum = null;
2189 for (int i = 0; i < MAX_DATABASE_RETRY_COUNT; i++)
2191 pEnum = db.ExecuteStatementN(*pStmt);
2192 r = GetLastResult();
2194 if (r != E_OBJECT_LOCKED)
2200 SysLog(NID_APP, "RetryCount[%d] ExecuteStatementN - E_OBJECT_LOCKED", i);
2210 } } } // Tizen::App::Package