Add package filter API
authorDuyoung Jang <duyoung.jang@samsung.com>
Mon, 25 Mar 2013 06:54:22 +0000 (15:54 +0900)
committerDuyoung Jang <duyoung.jang@samsung.com>
Mon, 25 Mar 2013 06:54:22 +0000 (15:54 +0900)
Change-Id: I8abe5717350f7e45c8a7d58ceb613460bda395c0
Signed-off-by: Duyoung Jang <duyoung.jang@samsung.com>
src/app/inc/FAppPkg_PackageManagerImpl.h
src/app/package/FAppPkg_PackageInfoImpl.cpp
src/app/package/FAppPkg_PackageManagerImpl.cpp

index 3c59004..cc2874c 100755 (executable)
@@ -60,6 +60,10 @@ static const int MAX_DATABASE_RETRY_COUNT = 30;
 static const wchar_t PACKAGE_DATABASE_FILE_NAME[] = L"/opt/usr/dbspace/.app-package.db";
 
 // PackageFilter
+static const wchar_t PACKAGE_FILTER_UNINSTALLABLE[] = L"http://tizen.org/package/uninstallable";
+static const wchar_t PACKAGE_FILTER_DOWNLOADED[] = L"http://tizen.org/package/downloaded";
+static const wchar_t PACKAGE_FILTER_EXTERNAL_STORAGE[] = L"http://tizen.org/package/externalstorage";
+static const wchar_t PACKAGE_FILTER_APP_SETTING[] = L"http://tizen.org/package/appsetting";
 
 // PackageAppFilter
 static const wchar_t PACKAGE_APP_FILTER_MENUICON_VISIBLE[] = L"http://tizen.org/package/app/menuiconvisible";
@@ -135,6 +139,7 @@ public:
        Tizen::Base::Collection::IList* GetPackageAppInfoListN(const Tizen::Base::Collection::IMap& packageAppFilterMap) const;
        Tizen::Base::Collection::IList* GetPackageAppInfoListN(const Tizen::Base::Collection::IMap& packageFilterMap, const Tizen::Base::Collection::IMap& packageAppFilterMap) const;
 
+       static int PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData);
        static int PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData);
 
        void SendPackageEvent(PackageType type, const PackageId& packageId, const char* eventKey, const char* eventValue);
index 4151206..4843be0 100755 (executable)
@@ -382,8 +382,6 @@ _PackageInfoImpl::GetPackageAppInfoN(const AppId& appId) const
        {
                SysTryReturn(NID_APP, __pPackageAppInfoList, null, E_SYSTEM, "__pPackageAppInfoList must not be null.");
 
-               result r = E_SUCCESS;
-
                for (int i = 0; i < __pPackageAppInfoList->GetCount(); i++)
                {
                        PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(__pPackageAppInfoList->GetAt(i));
index ec6b152..87a7a32 100755 (executable)
@@ -360,7 +360,7 @@ _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& pa
 {
        SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
        SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
-       SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_FILE_NOT_FOUND, "packagePath is not existed.");
+       SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
 
        String extension = File::GetFileExtension(packagePath);
        SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
@@ -773,7 +773,89 @@ _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
 {
        SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
 
-       return null;
+       std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
+       SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
+
+       int res = 0;
+       ArrayList* pList = null;
+       pkgmgrinfo_pkginfo_filter_h handle = null;
+
+       res = pkgmgrinfo_pkginfo_filter_create(&handle);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
+
+       while(pEnum->MoveNext() == E_SUCCESS)
+       {
+               String* pKey = static_cast< String* >(pEnum->GetKey());
+               SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
+
+               Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
+               SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
+
+               bool value = pVal->ToBool();
+
+               SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
+
+               if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
+               {
+                       String installedStorage;
+                       if (value == true)
+                       {
+                               installedStorage = L"installed_external";
+                       }
+                       else
+                       {
+                               installedStorage = L"installed_internal";
+                       }
+
+                       std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
+                       SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
+
+                       SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
+
+                       res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
+               }
+               else
+               {
+                       SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
+               }
+       }
+
+       pList = new (std::nothrow) ArrayList();
+       SysTryCatch(NID_APP, pList, , E_OUT_OF_MEMORY, "ArrayList creation failure.");
+       pList->Construct();
+
+       res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList);
+       if (res != 0)
+       {
+               SysLog(NID_APP, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() is failed. result = [%d]", res);
+
+               pList->RemoveAll(true);
+               pList = null;
+       }
+
+CATCH:
+       if (handle)
+       {
+               pkgmgrinfo_pkginfo_filter_destroy(handle);
+       }
+
+       return pList;
 }
 
 IList*
@@ -858,6 +940,32 @@ _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const
 }
 
 int
+_PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
+{
+       SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
+       SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
+
+       result r = E_SUCCESS;
+       int res = PMINFO_R_OK;
+       char* pPackageId = null;
+       ArrayList* pList = (ArrayList*)pUserData;
+
+       res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
+
+       std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
+       SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
+
+       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
+       r = pPackageInfoImpl->Construct(pPackageId);
+       SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
+
+       pList->Add(*pPackageInfo.release());
+
+       return 0;
+}
+
+int
 _PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
 {
        SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");