Add to cache pkg & appinfo 23/261023/48
authorChanggyu Choi <changyu.choi@samsung.com>
Thu, 8 Jul 2021 11:31:17 +0000 (20:31 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 5 Jan 2022 07:42:30 +0000 (07:42 +0000)
It is very expensive cost that access the sqlite db.
If getting pkg or app info query is called,
the server caches the info lists.
The cache data is released, when the set query was called.

Change-Id: I83380e1726bd7ae2acac6860cce05ce04326830e
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
82 files changed:
CMakeLists.txt
include/pkgmgrinfo_basic.h
packaging/pkgmgr-info.service
src/client/pkginfo_client.cc
src/common/parcel/appinfo_parcelable.cc
src/common/parcel/appinfo_parcelable.hh
src/common/parcel/pkginfo_parcelable.cc
src/common/parcel/pkginfo_parcelable.hh
src/manager/pkginfo_manager.cc
src/pkgmgrinfo_basic.c
src/server/CMakeLists.txt
src/server/appinfo_internal.c
src/server/database/abstract_db_handler.hh
src/server/database/appinfo_cache_db_handler.cc [new file with mode: 0644]
src/server/database/appinfo_cache_db_handler.hh [new file with mode: 0644]
src/server/database/appinfo_db_handler.cc
src/server/database/appinfo_db_handler.hh
src/server/database/db_handle_provider.cc
src/server/database/db_handle_provider.hh
src/server/database/pkg_get_cache_db_handler.cc [new file with mode: 0644]
src/server/database/pkg_get_cache_db_handler.hh [new file with mode: 0644]
src/server/database/pkg_get_db_handler.cc
src/server/database/pkg_get_db_handler.hh
src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/appid_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/appid_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/category_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/category_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/component_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/component_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/default_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/default_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/exec_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/exec_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/operation_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/operation_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/storage_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/storage_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/type_app_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/app_filter_checker/type_app_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/app_filter_checker_base.hh [new file with mode: 0644]
src/server/filter_checker/filter_checker_list.hh [new file with mode: 0644]
src/server/filter_checker/filter_checker_provider.cc [new file with mode: 0644]
src/server/filter_checker/filter_checker_provider.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.cc [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.hh [new file with mode: 0644]
src/server/filter_checker/pkg_filter_checker_base.hh [new file with mode: 0644]
src/server/pkginfo_internal.c
src/server/request_handler/get_appinfo_request_handler.cc
src/server/request_handler/get_appinfo_request_handler.hh
src/server/request_handler/get_pkginfo_request_handler.cc
src/server/request_handler/get_pkginfo_request_handler.hh
src/server/request_handler/set_pkginfo_request_handler.cc
src/server/sqlite_util_internal.c
src/server/worker_thread.cc
test/unit_tests/parcel_utils.cc
test/unit_tests/parcel_utils.hh
test/unit_tests/test_parcel.cc
test/unit_tests/test_parser_db_handlers.cc

index 135676d..5c27521 100644 (file)
@@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_SOURCE_DIR}/src/common/parcel
   ${CMAKE_SOURCE_DIR}/src/server
   ${CMAKE_SOURCE_DIR}/src/server/cynara_checker
+  ${CMAKE_SOURCE_DIR}/src/server/filter_checker
   ${CMAKE_SOURCE_DIR}/src/server/database
   ${CMAKE_SOURCE_DIR}/src/server/request_handler
 )
index 6b0de57..de9c71b 100644 (file)
@@ -206,6 +206,7 @@ typedef struct application_x {
        GList *appcontrol; /*element*/
        GList *splashscreens; /*element*/
        GList *res_control; /*element*/
+       GList *privileges; /*element*/
 } application_x;
 
 typedef struct package_x {
@@ -241,6 +242,7 @@ typedef struct package_x {
        char *locale;   /*no xml part*/
        char *res_type; /**< res type, attr*/
        char *res_version;      /**< res version, attr*/
+       char *is_disabled; /**< Flag that indicates if the package is disabled or not, no xml part*/
        GList *icon;            /**< package icon, element*/
        GList *label;           /**< package label, element*/
        GList *author;          /**< package author, element*/
index 34b239b..fac20e3 100755 (executable)
@@ -12,8 +12,6 @@ ExecStart=/usr/bin/pkginfo-server
 Type=notify
 User=app_fw
 Group=app_fw
-CPUSchedulingPriority=1
-CPUSchedulingPolicy=rr
 
 [Install]
 WantedBy=basic.target
index 37b7f03..4d179f9 100644 (file)
@@ -130,7 +130,7 @@ bool PkgInfoClient::RequestHandlerDirectAccess() {
   static void* (*dl_func)(int, unsigned char*, int, const char *);
 
   if (handle == nullptr) {
-    handle = dlopen(LIBPKGMGR_INFO, RTLD_LOCAL | RTLD_LAZY);
+    handle = dlopen(LIBPKGMGR_INFO, RTLD_GLOBAL | RTLD_LAZY);
     if (!handle) {
       LOG(ERROR) << "Failed to open library: " << LIBPKGMGR_INFO
           << ", : " << dlerror();
index 740de2a..65cbf81 100644 (file)
@@ -346,23 +346,20 @@ AppInfoParcelable::AppInfoParcelable()
     : AbstractParcelable(0, ParcelableType::AppInfo), auto_release_(true) {}
 
 AppInfoParcelable::AppInfoParcelable(int ret,
-    std::vector<application_x*>&& app_list, bool auto_release)
+    std::vector<std::shared_ptr<application_x>>&& app_list, bool auto_release)
     : AbstractParcelable(0, ParcelableType::AppInfo, ret),
     app_list_(std::move(app_list)), auto_release_(auto_release) {}
 
 AppInfoParcelable::~AppInfoParcelable() {
-  if (!auto_release_)
-    return;
-
-  for (auto app : app_list_)
-    pkgmgrinfo_basic_free_application(app);
 }
 
-const std::vector<application_x*>& AppInfoParcelable::GetAppInfo() {
+const std::vector<std::shared_ptr<application_x>>&
+    AppInfoParcelable::GetAppInfo() {
   return app_list_;
 }
 
-std::vector<application_x*> AppInfoParcelable::ExtractAppInfo() {
+std::vector<std::shared_ptr<application_x>>
+    AppInfoParcelable::ExtractAppInfo() {
   return std::move(app_list_);
 }
 
@@ -505,8 +502,8 @@ void AppInfoParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
   AbstractParcelable::WriteToParcel(parcel);
   WriteInt(parcel, app_list_.size());
 
-  for (const auto app : app_list_)
-    WriteApplication(parcel, app);
+  for (auto& app : app_list_)
+    WriteApplication(parcel, app.get());
 }
 
 void AppInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
@@ -516,7 +513,8 @@ void AppInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
   ReadInt(parcel, &len);
 
   for (int i = 0; i < len ; ++i)
-    app_list_.emplace_back(ReadApplication(parcel));
+    app_list_.emplace_back(ReadApplication(parcel),
+        [] (application_x*) -> void {});
 }
 
 }  // namespace parcel
index 875e1aa..4f67234 100644 (file)
@@ -17,11 +17,12 @@ namespace parcel {
 class EXPORT_API AppInfoParcelable : public AbstractParcelable {
  public:
   AppInfoParcelable();
-  AppInfoParcelable(int ret, std::vector<application_x*>&& app_list,
+  AppInfoParcelable(int ret,
+      std::vector<std::shared_ptr<application_x>>&& app_list,
       bool auto_release = true);
   ~AppInfoParcelable();
-  const std::vector<application_x*>& GetAppInfo();
-  std::vector<application_x*> ExtractAppInfo();
+  const std::vector<std::shared_ptr<application_x>>& GetAppInfo();
+  std::vector<std::shared_ptr<application_x>> ExtractAppInfo();
 
   void WriteToParcel(tizen_base::Parcel* parcel) const override;
   void ReadFromParcel(tizen_base::Parcel* parcel) override;
@@ -63,7 +64,7 @@ class EXPORT_API AppInfoParcelable : public AbstractParcelable {
   void ReadResControl(tizen_base::Parcel* parcel, GList** list);
   application_x* ReadApplication(tizen_base::Parcel* parcel);
 
-  std::vector<application_x*> app_list_;
+  std::vector<std::shared_ptr<application_x>> app_list_;
   bool auto_release_;
 };
 
index 656995b..032d275 100644 (file)
@@ -121,11 +121,11 @@ void PkgInfoParcelable::WriteProvidesAppdefinedPrivileges(
 
 void PkgInfoParcelable::WriteApplication(tizen_base::Parcel* parcel,
     GList* application) const {
-  std::vector<application_x*> app_vt;
+  std::vector<std::shared_ptr<application_x>> app_vt;
 
   for (GList* tmp = application; tmp; tmp = tmp->next) {
     application_x* ptr = reinterpret_cast<application_x*>(tmp->data);
-    app_vt.push_back(ptr);
+    app_vt.emplace_back(ptr, [] (application_x*) -> void {});
   }
 
   AppInfoParcelable apps(0, std::move(app_vt), false);
@@ -220,6 +220,7 @@ void PkgInfoParcelable::WritePackage(tizen_base::Parcel* parcel,
   WriteString(parcel, package->locale);
   WriteString(parcel, package->res_type);
   WriteString(parcel, package->res_version);
+  WriteString(parcel, package->is_disabled);
   WriteIcon(parcel, package->icon);
   WriteLabel(parcel, package->label);
   WriteAuthor(parcel, package->author);
@@ -356,10 +357,10 @@ void PkgInfoParcelable::ReadApplication(
   AppInfoParcelable apps;
   parcel->ReadParcelable(&apps);
 
-  std::vector<application_x*> vt = apps.ExtractAppInfo();
+  std::vector<std::shared_ptr<application_x>> vt = apps.ExtractAppInfo();
 
-  for (application_x* application : vt)
-    *list = g_list_append(*list, application);
+  for (auto& application : vt)
+    *list = g_list_append(*list, application.get());
 }
 
 void PkgInfoParcelable::ReadCompatibility(
@@ -472,6 +473,7 @@ package_x* PkgInfoParcelable::ReadPackage(tizen_base::Parcel* parcel) {
   ReadString(parcel, &package->locale);
   ReadString(parcel, &package->res_type);
   ReadString(parcel, &package->res_version);
+  ReadString(parcel, &package->is_disabled);
   ReadIcon(parcel, &package->icon);
   ReadLabel(parcel, &package->label);
   ReadAuthor(parcel, &package->author);
@@ -494,31 +496,27 @@ PkgInfoParcelable::PkgInfoParcelable()
     write_type_(PkgWriteType::None), auto_release_(true) {}
 
 PkgInfoParcelable::PkgInfoParcelable(
-    uid_t uid, std::vector<package_x*>&& pkg_list,
+    uid_t uid, std::vector<std::shared_ptr<package_x>>&& pkg_list,
     PkgWriteType write_type, bool auto_release)
     : AbstractParcelable(uid, ParcelableType::PkgInfo),
     pkg_list_(std::move(pkg_list)), write_type_(write_type),
     auto_release_(auto_release) {}
 
 PkgInfoParcelable::PkgInfoParcelable(
-    int ret, std::vector<package_x*>&& pkg_list, bool auto_release)
+    int ret, std::vector<std::shared_ptr<package_x>>&& pkg_list,
+    bool auto_release)
     : AbstractParcelable(0, ParcelableType::PkgInfo, ret),
     pkg_list_(std::move(pkg_list)), write_type_(PkgWriteType::None),
     auto_release_(auto_release) {}
 
 PkgInfoParcelable::~PkgInfoParcelable() {
-  if (!auto_release_)
-    return;
-
-  for (auto pkg : pkg_list_)
-    pkgmgrinfo_basic_free_package(pkg);
 }
 
-const std::vector<package_x*>& PkgInfoParcelable::GetPkgInfo() {
+const std::vector<std::shared_ptr<package_x>>& PkgInfoParcelable::GetPkgInfo() {
   return pkg_list_;
 }
 
-std::vector<package_x*> PkgInfoParcelable::ExtractPkgInfo() {
+std::vector<std::shared_ptr<package_x>> PkgInfoParcelable::ExtractPkgInfo() {
   return std::move(pkg_list_);
 }
 
@@ -532,8 +530,8 @@ void PkgInfoParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
 
   WriteInt(parcel, pkg_list_.size());
 
-  for (auto pkg : pkg_list_)
-    WritePackage(parcel, pkg);
+  for (auto& pkg : pkg_list_)
+    WritePackage(parcel, pkg.get());
 }
 
 void PkgInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
@@ -548,7 +546,7 @@ void PkgInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
   ReadInt(parcel, &len);
 
   for (int i = 0; i < len ; ++i)
-    pkg_list_.emplace_back(ReadPackage(parcel));
+    pkg_list_.emplace_back(ReadPackage(parcel), [] (package_x*) -> void {});
 }
 
 }  // namespace parcel
index 8070c35..27dd14e 100644 (file)
@@ -19,13 +19,14 @@ namespace parcel {
 class EXPORT_API PkgInfoParcelable : public AbstractParcelable {
  public:
   PkgInfoParcelable();
-  PkgInfoParcelable(uid_t uid, std::vector<package_x*>&& pkg_list,
+  PkgInfoParcelable(uid_t uid,
+      std::vector<std::shared_ptr<package_x>>&& pkg_list,
       PkgWriteType write_type, bool auto_release = true);
-  PkgInfoParcelable(int ret, std::vector<package_x*>&& pkg_list,
+  PkgInfoParcelable(int ret, std::vector<std::shared_ptr<package_x>>&& pkg_list,
       bool auto_release = true);
   ~PkgInfoParcelable();
-  const std::vector<package_x*>& GetPkgInfo();
-  std::vector<package_x*> ExtractPkgInfo();
+  const std::vector<std::shared_ptr<package_x>>& GetPkgInfo();
+  std::vector<std::shared_ptr<package_x>> ExtractPkgInfo();
   PkgWriteType GetWriteType();
 
   void WriteToParcel(tizen_base::Parcel* parcel) const override;
@@ -70,7 +71,7 @@ class EXPORT_API PkgInfoParcelable : public AbstractParcelable {
   void ReadResAllowedPackages(tizen_base::Parcel* parcel, GList** list);
   package_x* ReadPackage(tizen_base::Parcel* parcel);
 
-  std::vector<package_x*> pkg_list_;
+  std::vector<std::shared_ptr<package_x>> pkg_list_;
   PkgWriteType write_type_;
   bool auto_release_;
 };
index f9ff82c..2b72d05 100644 (file)
@@ -69,7 +69,7 @@ int ValidateParcelable(
   }
 
   if (parcel->GetType() != parcel_type) {
-    LOG(ERROR) << "Invalid parcelable Type";
+    LOG(ERROR) << "Invalid parcelable Type " << parcel->GetType() << ' ' << parcel_type;
     return PMINFO_R_ERROR;
   }
 
@@ -120,9 +120,9 @@ extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
     LOG(DEBUG) << "No packages meets given condition for user " << uid;
     return PMINFO_R_ENOENT;
   }
-  for (auto pkginfo : result_list)
-    g_hash_table_insert(packages, (gpointer)pkginfo->package,
-                        (gpointer)pkginfo);
+  for (auto& pkginfo : result_list)
+    g_hash_table_insert(packages, reinterpret_cast<gpointer>(pkginfo->package),
+                        reinterpret_cast<gpointer>(pkginfo.get()));
 
   return PMINFO_R_OK;
 }
@@ -185,10 +185,10 @@ extern "C" EXPORT_API int _appinfo_get_applications(uid_t uid,
   std::shared_ptr<pcp::AppInfoParcelable> return_parcel(
       std::static_pointer_cast<pcp::AppInfoParcelable>(ptr));
 
-  std::vector<application_x*> result_list = return_parcel->ExtractAppInfo();
-  for (application_x* app : result_list)
-    g_hash_table_insert(packages, (gpointer)app->appid,
-        (gpointer)app);
+  std::vector<std::shared_ptr<application_x>> result_list = return_parcel->ExtractAppInfo();
+  for (auto& app : result_list)
+    g_hash_table_insert(packages, reinterpret_cast<gpointer>(app->appid),
+        reinterpret_cast<gpointer>(app.get()));
 
   return PMINFO_R_OK;
 }
@@ -807,8 +807,9 @@ extern "C" EXPORT_API int _parser_insert_manifest_info(
     manifest_x* mfx, uid_t uid) {
   auto parcelable =
       std::make_shared<pcp::PkgInfoParcelable>(uid,
-          std::vector<package_x*>{mfx},
-          pkgmgr_common::PkgWriteType::Insert, false);
+          std::vector<std::shared_ptr<package_x>>(1,
+              std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+              pkgmgr_common::PkgWriteType::Insert, false);
 
   pkgmgr_client::PkgInfoClient client(parcelable, uid,
       pkgmgr_common::ReqType::SET_PKG_INFO);
@@ -823,8 +824,9 @@ extern "C" EXPORT_API int _parser_update_manifest_info(
     manifest_x* mfx, uid_t uid) {
   auto parcelable =
       std::make_shared<pcp::PkgInfoParcelable>(uid,
-          std::vector<package_x*>{mfx},
-          pkgmgr_common::PkgWriteType::Update, false);
+          std::vector<std::shared_ptr<package_x>>(1,
+              std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+              pkgmgr_common::PkgWriteType::Update, false);
 
   pkgmgr_client::PkgInfoClient client(parcelable, uid,
       pkgmgr_common::ReqType::SET_PKG_INFO);
@@ -839,8 +841,9 @@ extern "C" EXPORT_API int _parser_delete_manifest_info(
     manifest_x* mfx, uid_t uid) {
   auto parcelable =
       std::make_shared<pcp::PkgInfoParcelable>(uid,
-          std::vector<package_x*>{mfx},
-          pkgmgr_common::PkgWriteType::Delete, false);
+          std::vector<std::shared_ptr<package_x>>(1,
+              std::shared_ptr<package_x>(mfx, [] (package_x*) -> void {})),
+              pkgmgr_common::PkgWriteType::Delete, false);
 
   pkgmgr_client::PkgInfoClient client(parcelable, uid,
       pkgmgr_common::ReqType::SET_PKG_INFO);
index 8aafaca..6825959 100644 (file)
@@ -553,6 +553,8 @@ API void pkgmgrinfo_basic_free_package(package_x *package)
                free((void *)package->res_type);
        if (package->res_version)
                free((void *)package->res_version);
+       if (package->is_disabled)
+               free((void *)package->is_disabled);
 
        /*Free Icon*/
        g_list_free_full(package->icon, __ps_free_icon);
index 19ed9da..e8a7c9f 100644 (file)
@@ -3,12 +3,18 @@ SET(PKGINFO_SERVER "pkginfo-server")
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SERVER_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/cynara_checker CYNARA_CHECKER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/filter_checker/ FILTER_CHECKER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/filter_checker/pkg_filter_checker/ PKG_FILTER_CHECKER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/filter_checker/app_filter_checker/ APP_FILTER_CHECKER_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/database DATABASE_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/request_handler REQUEST_HANDLER_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/utils/ UTIL_SRCS)
 
 ADD_LIBRARY(pkgmgr-info-server SHARED
   ${CYNARA_CHECKER_SRCS}
+  ${FILTER_CHECKER_SRCS}
+  ${PKG_FILTER_CHECKER_SRCS}
+  ${APP_FILTER_CHECKER_SRCS}
   ${SERVER_SRCS}
   ${DATABASE_SRCS}
   ${REQUEST_HANDLER_SRCS}
@@ -40,4 +46,3 @@ TARGET_LINK_LIBRARIES(${PKGINFO_SERVER} PUBLIC pkgmgr-info-server pthread)
 
 SET_TARGET_PROPERTIES(${PKGINFO_SERVER} PROPERTIES LINKER_LANGUAGE CXX)
 INSTALL(TARGETS ${PKGINFO_SERVER} DESTINATION bin)
-
index ae5d8f2..d4f8b24 100644 (file)
@@ -391,6 +391,15 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, const char *locale,
 
        if (!filter)
                return PMINFO_R_OK;
+
+       if (g_slist_length(filter->list) == 0) {
+               joined = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO |
+                       E_PMINFO_APPINFO_JOIN_CATEGORY |
+                       E_PMINFO_APPINFO_JOIN_APP_CONTROL |
+                       E_PMINFO_APPINFO_JOIN_METADATA |
+                       E_PMINFO_APPINFO_JOIN_PRIVILEGE;
+       }
+
        strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
 
        for (list = filter->list; list; list = list->next) {
index e552a78..afbc4ae 100644 (file)
@@ -51,6 +51,7 @@ class EXPORT_API AbstractDBHandler {
   virtual bool Connect();
   int GetPID();
   uid_t GetUID();
+  std::vector<std::pair<std::string, uid_t>> GetDBPath();
   virtual std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
   void ClearDBHandle();
   const std::string& GetLocale();
@@ -58,7 +59,6 @@ class EXPORT_API AbstractDBHandler {
   static std::shared_timed_mutex lock_;
 
  private:
-  std::vector<std::pair<std::string, uid_t>> GetDBPath();
 
   pkgmgr_common::DBType db_type_;
   pkgmgr_common::DBOperationType op_type_;
@@ -72,4 +72,3 @@ class EXPORT_API AbstractDBHandler {
 }  // namespace pkgmgr_server
 
 #endif  // ABSTRACT_DB_HANDLER_HH_
-
diff --git a/src/server/database/appinfo_cache_db_handler.cc b/src/server/database/appinfo_cache_db_handler.cc
new file mode 100644 (file)
index 0000000..64462b2
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "appinfo_cache_db_handler.hh"
+
+#include <shared_mutex>
+#include <vector>
+
+#include "db_handle_provider.hh"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_debug.h"
+#include "utils/logging.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+AppInfoCacheDBHandler::AppInfoCacheDBHandler(uid_t uid, int pid)
+    : AppInfoDBHandler(uid, pid) {}
+
+int AppInfoCacheDBHandler::Execute() {
+  std::shared_lock<std::shared_timed_mutex> s(lock_);
+  SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+  SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+  bool write =
+      GetOpType() == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE;
+
+  std::vector<std::pair<sqlite3*, uid_t>> conn_list;
+  if (!Connect())
+    return PMINFO_R_ERROR;
+
+  conn_list = GetConnection();
+
+  int ret = PMINFO_R_OK;
+  std::string application;
+
+  for (auto* it = filter_->list; it != nullptr; it = g_slist_next(it)) {
+    auto node = reinterpret_cast<pkgmgrinfo_node_x*>(it->data);
+    if (node->prop == E_PMINFO_APPINFO_PROP_APP_ID) {
+      application = node->value;
+      break;
+    }
+  }
+
+  std::vector<std::shared_ptr<application_x>> app_list;
+  for (auto& conn : conn_list) {
+    ret = DBHandleProvider::GetInst(conn.second)
+              .UpdateCache(conn.first, GetPID(), uid_, write, GetLocale());
+    if (ret != PMINFO_R_OK) {
+      LOG(DEBUG) << "Failed to update appinfo cache: " << ret;
+      break;
+    }
+
+    app_list = DBHandleProvider::GetInst(conn.second)
+                   .GetApplications(GetPID(), write, filter_, application);
+
+    handle_list_.reserve(app_list.size() + handle_list_.size());
+    std::move(std::begin(app_list), std::end(app_list),
+              std::back_inserter(handle_list_));
+  }
+
+  if (handle_list_.empty())
+    ret = PMINFO_R_ENOENT;
+
+  return ret;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/database/appinfo_cache_db_handler.hh b/src/server/database/appinfo_cache_db_handler.hh
new file mode 100644 (file)
index 0000000..ec29b64
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APPINFO_CACHE_DB_HANDLER_HH_
+#define APPINFO_CACHE_DB_HANDLER_HH_
+
+#include <vector>
+
+#include <sys/types.h>
+
+#include "appinfo_db_handler.hh"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API AppInfoCacheDBHandler : public AppInfoDBHandler {
+ public:
+  AppInfoCacheDBHandler(uid_t uid, int pid);
+  int Execute() override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // APPINFO_CACHE_DB_HANDLER_HH_
index 9434159..8fe5e9f 100644 (file)
 namespace {
 
 gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
-  application_x* appinfo = static_cast<application_x*>(value);
-  std::vector<application_x*>* app_list =
-      static_cast<std::vector<application_x*>*>(user_data);
-  app_list->emplace_back(appinfo);
+  application_x* info = static_cast<application_x*>(value);
+  std::vector<std::shared_ptr<application_x>>* app_list =
+      static_cast<std::vector<std::shared_ptr<application_x>>*>(user_data);
+  app_list->push_back(
+      std::shared_ptr<application_x>(info, pkgmgrinfo_basic_free_application));
 
   return true;
 }
 
-void __free_applications(gpointer data) {
-  pkgmgrinfo_basic_free_application(reinterpret_cast<application_x*>(data));
-}
-
 }  // namespace
 
 namespace pkgmgr_server {
@@ -50,7 +47,7 @@ AppInfoDBHandler::AppInfoDBHandler(uid_t uid, int pid)
 
 AppInfoDBHandler::~AppInfoDBHandler() {}
 
-std::vector<application_x*> AppInfoDBHandler::GetAppHandle() {
+std::vector<std::shared_ptr<application_x>> AppInfoDBHandler::GetAppHandle() {
   return std::move(handle_list_);
 }
 
@@ -66,8 +63,8 @@ int AppInfoDBHandler::Execute() {
   if (!Connect())
     return PMINFO_R_ERROR;
 
-  GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
-      NULL, __free_applications);
+  GHashTable* list =
+      g_hash_table_new_full(g_str_hash, g_str_equal, nullptr, nullptr);
   std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
   int ret = PMINFO_R_OK;
   for (auto& conn : conn_list) {
index e239ef5..4cbf651 100644 (file)
 #ifndef APPINFO_DB_HANDLER_HH_
 #define APPINFO_DB_HANDLER_HH_
 
-#include <vector>
-
 #include <sys/types.h>
 
+#include <memory>
+#include <vector>
+
 #include "abstract_db_handler.hh"
 #include "pkgmgrinfo_basic.h"
 #include "pkgmgrinfo_private.h"
@@ -36,13 +37,13 @@ class EXPORT_API AppInfoDBHandler : public AbstractDBHandler{
  public:
   AppInfoDBHandler(uid_t uid, int pid);
   ~AppInfoDBHandler();
-  std::vector<application_x*> GetAppHandle();
+  std::vector<std::shared_ptr<application_x>> GetAppHandle();
   void SetFilter(pkgmgrinfo_filter_x* filter);
-  int Execute() override;
+  virtual int Execute();
 
- private:
+ protected:
   pkgmgrinfo_filter_x* filter_;
-  std::vector<application_x*> handle_list_;
+  std::vector<std::shared_ptr<application_x>> handle_list_;
   uid_t uid_;
 };
 
@@ -50,4 +51,3 @@ class EXPORT_API AppInfoDBHandler : public AbstractDBHandler{
 }  // namespace pkgmgr_server
 
 #endif  // APPINFO_DB_HANDLER_HH_
-
index 7f8582b..43f00b2 100644 (file)
@@ -17,6 +17,7 @@
 #include "db_handle_provider.hh"
 
 #include <fcntl.h>
+#include <glib.h>
 #include <sys/types.h>
 
 #include <tzplatform_config.h>
 
 #include "utils/logging.hh"
 
-#include "pkgmgrinfo_debug.h"
 #include "pkgmgr-info.h"
+#include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_internal.h"
+#include "pkgmgrinfo_private.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -37,8 +40,6 @@
 
 namespace {
 
-constexpr uid_t REGULAR_USER = 5000;
-
 uid_t globaluser_uid = -1;
 
 uid_t GetGlobalUID() {
@@ -70,8 +71,8 @@ std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>>
     DBHandleProvider::provider_;
 bool DBHandleProvider::is_memory_global_ = false;
 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
-    DBHandleProvider::global_parser_memory_db_handle_(
-        nullptr, sqlite3_close_v2);
+    DBHandleProvider::global_parser_memory_db_handle_(nullptr,
+                                                      sqlite3_close_v2);
 std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
     DBHandleProvider::cert_memory_db_handle_(nullptr, sqlite3_close_v2);
 std::string DBHandleProvider::global_parser_file_db_path_;
@@ -79,8 +80,10 @@ std::string DBHandleProvider::cert_file_db_path_;
 std::unordered_set<pid_t> DBHandleProvider::pid_list_;
 std::recursive_mutex DBHandleProvider::lock_;
 
-DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
-    is_memory_(false), parser_memory_db_handle_(nullptr, sqlite3_close_v2) {
+DBHandleProvider::DBHandleProvider(uid_t uid)
+    : uid_(uid),
+      is_memory_(false),
+      parser_memory_db_handle_(nullptr, sqlite3_close_v2) {
   char* tmp_path;
 
   if (global_parser_file_db_path_.empty()) {
@@ -98,12 +101,13 @@ DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
   free(tmp_path);
 
   parser_memory_db_path_ = "file:parserdb" +
-      std::to_string(static_cast<int>(uid_)) + "?mode=memory&cache=shared";
+                           std::to_string(static_cast<int>(uid_)) +
+                           "?mode=memory&cache=shared";
 }
 
 DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
-  static std::mutex singleton_lock;
-  std::unique_lock<std::mutex> u(singleton_lock);
+  static std::mutex singleton_lock_;
+  std::unique_lock<std::mutex> u(singleton_lock_);
 
   uid = ConvertUID(uid);
   auto& prov = provider_[uid];
@@ -183,26 +187,26 @@ std::string DBHandleProvider::GetCertDBPath(pid_t pid, bool write) {
 }
 
 sqlite3* DBHandleProvider::GetMemoryDBHandle(const std::string& filedb_path,
-    const std::string& memorydb_path) {
+                                             const std::string& memorydb_path) {
   sqlite3* memorydb = nullptr;
   sqlite3* filedb = nullptr;
   int ret = sqlite3_open_v2(memorydb_path.c_str(), &memorydb,
-      SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, nullptr);
+                            SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, nullptr);
   if (ret != SQLITE_OK) {
     LOG(ERROR) << "Failed to open memory DB " << ret << ": " << memorydb_path;
     return nullptr;
   }
 
-  ret = sqlite3_open_v2(filedb_path.c_str(), &filedb,
-      SQLITE_OPEN_READONLY, nullptr);
+  ret = sqlite3_open_v2(filedb_path.c_str(), &filedb, SQLITE_OPEN_READONLY,
+                        nullptr);
   if (ret != SQLITE_OK) {
     LOG(ERROR) << "Failed to open file DB " << ret << ": " << filedb_path;
     sqlite3_close_v2(memorydb);
     return nullptr;
   }
 
-  sqlite3_backup* backup = sqlite3_backup_init(memorydb, "main",
-      filedb, "main");
+  sqlite3_backup* backup =
+      sqlite3_backup_init(memorydb, "main", filedb, "main");
   if (backup == nullptr) {
     LOG(ERROR) << "Failed to backup for memory DB";
     sqlite3_close_v2(memorydb);
@@ -221,18 +225,18 @@ void DBHandleProvider::SetMemoryMode(pid_t pid) {
   if (is_memory_global_ && is_memory_)
     return;
 
-  sqlite3* parser_db = GetMemoryDBHandle(parser_file_db_path_,
-      parser_memory_db_path_);
+  sqlite3* parser_db =
+      GetMemoryDBHandle(parser_file_db_path_, parser_memory_db_path_);
   if (parser_db != nullptr)
     parser_memory_db_handle_.reset(parser_db);
 
-  if (is_memory_ == is_memory_global_) {  /* first call */
+  if (is_memory_ == is_memory_global_) {
     sqlite3* global_parser_file_db = GetMemoryDBHandle(
         global_parser_file_db_path_, global_parser_memory_db_path);
     if (global_parser_file_db)
       global_parser_memory_db_handle_.reset(global_parser_file_db);
-    sqlite3* cert_db = GetMemoryDBHandle(cert_file_db_path_,
-        cert_memory_db_path);
+    sqlite3* cert_db =
+        GetMemoryDBHandle(cert_file_db_path_, cert_memory_db_path);
     if (cert_db != nullptr)
       cert_memory_db_handle_.reset(cert_db);
 
@@ -242,6 +246,9 @@ void DBHandleProvider::SetMemoryMode(pid_t pid) {
 
   is_memory_ = true;
   is_memory_global_ = true;
+  old_pkg_map_ = std::move(pkg_map_);
+  old_app_map_ = std::move(app_map_);
+  released_ = true;
   LOG(DEBUG) << "Set Memory mode : Memory";
 }
 
@@ -262,6 +269,8 @@ void DBHandleProvider::UnsetMemoryMode(pid_t pid) {
 
   is_memory_ = false;
   is_memory_global_ = false;
+  old_pkg_map_.clear();
+  old_app_map_.clear();
   LOG(DEBUG) << "Set Memory mode : File";
 }
 
@@ -269,5 +278,175 @@ bool DBHandleProvider::IsMemoryDBActive(pid_t pid, bool write) {
   return (is_memory_ && pid_list_.find(pid) == pid_list_.end() && !write);
 }
 
+void DBHandleProvider::TrimCache() {
+  std::unique_lock<std::recursive_mutex> u(lock_);
+  if (!released_)
+    ReleaseCache();
+}
+
+void DBHandleProvider::ReleaseCache() {
+  app_map_.clear();
+  pkg_map_.clear();
+  released_ = true;
+}
+
+bool DBHandleProvider::NeedUpdate(pid_t pid, bool write,
+    const std::string& locale) {
+  std::unique_lock<std::recursive_mutex> u(lock_);
+  return (!IsMemoryDBActive(pid, write) && (locale_ != locale || released_));
+}
+
+int DBHandleProvider::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write,
+    const std::string& locale) {
+  if (!NeedUpdate(pid, write, locale))
+    return PMINFO_R_OK;
+
+  std::unique_lock<std::recursive_mutex> u(lock_);
+  if (!released_)
+    ReleaseCache();
+
+  locale_ = locale;
+
+  GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal);
+  if (list == nullptr) {
+    LOG(ERROR) << "Out of memory";
+    return PMINFO_R_ERROR;
+  }
+
+  auto tmp_filter = reinterpret_cast<pkgmgrinfo_filter_x*>(
+      calloc(1, sizeof(pkgmgrinfo_filter_x)));
+  if (tmp_filter == nullptr) {
+    LOG(ERROR) << "Out of memory";
+    g_hash_table_destroy(list);
+    return PMINFO_R_ERROR;
+  }
+
+  int ret = pkginfo_internal_filter_get_list(db, tmp_filter, uid_,
+                                             locale_.c_str(), list);
+  if (ret == PMINFO_R_OK) {
+    GHashTableIter iter;
+    gpointer value;
+    g_hash_table_iter_init(&iter, list);
+    while (g_hash_table_iter_next(&iter, nullptr, &value)) {
+      auto* pkg = reinterpret_cast<package_x*>(value);
+      AddPackage(pkg->package, pkg);
+    }
+  }
+
+  g_hash_table_destroy(list);
+  if (ret == PMINFO_R_ERROR) {
+    free(tmp_filter);
+    return ret;
+  }
+
+  list = g_hash_table_new(g_str_hash, g_str_equal);
+  ret = appinfo_internal_filter_get_list(db, tmp_filter, uid_, uid,
+                                         locale_.c_str(), list);
+  free(tmp_filter);
+  if (ret == PMINFO_R_OK) {
+    GHashTableIter iter;
+    gpointer value;
+    g_hash_table_iter_init(&iter, list);
+    while (g_hash_table_iter_next(&iter, nullptr, &value)) {
+      auto* app = reinterpret_cast<application_x*>(value);
+      app->privileges = pkg_map_[app->package].front()->privileges;
+      AddApplication(app->appid, app);
+    }
+  }
+  g_hash_table_destroy(list);
+  released_ = false;
+
+  return ret;
+}
+
+std::vector<std::shared_ptr<package_x>> DBHandleProvider::GetPackages(
+    pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+    const std::string& package) {
+  auto& pkg_map = (IsMemoryDBActive(pid, write) ? old_pkg_map_ : pkg_map_);
+
+  std::vector<std::shared_ptr<package_x>> ret;
+  for (auto& info : pkg_map[package]) {
+    bool pass = true;
+    for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) {
+      auto node = reinterpret_cast<pkgmgrinfo_node_x*>(it->data);
+      auto* checker = FilterCheckerProvider::GetInst().
+          GetPkgFilterChecker(node->prop);
+      if (!checker->CheckFilter(node, info.get())) {
+        pass = false;
+        break;
+      }
+    }
+    if (pass)
+      ret.push_back(info);
+  }
+
+  return ret;
+}
+
+void DBHandleProvider::AddPackage(std::string package, package_x* info) {
+  auto ptr = std::shared_ptr<package_x>(info, pkgmgrinfo_basic_free_package);
+  pkg_map_[package].push_back(ptr);
+  pkg_map_[""].push_back(std::move(ptr));
+}
+
+std::vector<std::shared_ptr<application_x>> DBHandleProvider::GetApplications(
+    pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+    const std::string& app) {
+  auto& app_map = (IsMemoryDBActive(pid, write) ? old_app_map_ : app_map_);
+
+  /* make metadata filter map */
+  std::unordered_map<std::string, std::string> metadata_map;
+  for (auto* it = filter->list_metadata; it != nullptr; it = g_slist_next(it)) {
+    auto node = reinterpret_cast<pkgmgrinfo_metadata_node_x*>(it->data);
+    if (node->key == nullptr)
+      continue;
+
+    metadata_map[node->key] = (node->value ? node->value : "");
+  }
+
+  std::vector<std::shared_ptr<application_x>> ret;
+  for (auto& info : app_map[app]) {
+    bool pass = true;
+    for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) {
+      auto node = reinterpret_cast<pkgmgrinfo_node_x*>(it->data);
+      auto* checker = FilterCheckerProvider::GetInst().
+          GetAppFilterChecker(node->prop);
+      if (!checker->CheckFilter(node, info.get())) {
+        pass = false;
+        break;
+      }
+    }
+    if (!pass)
+      continue;
+
+    if (!metadata_map.empty()) {
+      pass = false;
+      for (auto* it = info->metadata; it != nullptr; it = g_list_next(it)) {
+        auto* node = reinterpret_cast<metadata_x*>(it->data);
+        if (node->key != nullptr) {
+          auto metadata = metadata_map.find(node->key);
+          if (metadata != metadata_map.end() &&
+              strstr(node->value ? node->value : "",
+                  metadata->second.c_str()) != nullptr) {
+            pass = true;
+            break;
+          }
+        }
+      }
+    }
+
+    if (pass)
+      ret.push_back(info);
+  }
+  return ret;
+}
+
+void DBHandleProvider::AddApplication(std::string app, application_x* info) {
+  auto ptr =
+      std::shared_ptr<application_x>(info, pkgmgrinfo_basic_free_application);
+  app_map_[app].push_back(ptr);
+  app_map_[""].push_back(std::move(ptr));
+}
+
 }  // namespace database
 }  // namespace pkgmgr_server
index 329e9ca..0258a08 100644 (file)
 #include <stdlib.h>
 #include <sys/types.h>
 
-#include <string>
 #include <memory>
 #include <mutex>
+#include <string>
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
 
+#include "filter_checker_provider.hh"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
 #include "shared_object.hh"
 
 namespace pkgmgr_server {
@@ -42,21 +45,33 @@ class EXPORT_API DBHandleProvider {
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
   static bool IsCrashedWriteRequest();
-  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(
-      int pid, bool write);
+  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid,
+                                                             bool write);
   std::string GetCertDBPath(int pid, bool write);
   void SetMemoryMode(pid_t pid);
   void UnsetMemoryMode(pid_t pid);
+  bool NeedUpdate(pid_t pid, bool write, const std::string& locale);
+  int UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write,
+                  const std::string& locale);
+  std::vector<std::shared_ptr<package_x>> GetPackages(
+      pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+      const std::string& package);
+  std::vector<std::shared_ptr<application_x>> GetApplications(
+      pid_t pid, bool write, pkgmgrinfo_filter_x* filter,
+      const std::string& app);
+  void TrimCache();
 
  private:
-  DBHandleProvider(uid_t uid);
+  explicit DBHandleProvider(uid_t uid);
   sqlite3* GetMemoryDBHandle(const std::string& filedb_path,
-      const std::string& memorydb_path);
+                             const std::string& memorydb_path);
   bool IsMemoryDBActive(pid_t pid, bool write);
+  void ReleaseCache();
+  void AddPackage(std::string package, package_x* info);
+  void AddApplication(std::string app, application_x* info);
 
  private:
-  static std::unordered_map<uid_t,
-      std::unique_ptr<DBHandleProvider>> provider_;
+  static std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>> provider_;
   static bool is_memory_global_;
   static std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
       global_parser_memory_db_handle_;
@@ -69,10 +84,20 @@ class EXPORT_API DBHandleProvider {
 
   uid_t uid_;
   bool is_memory_;
-  std::unique_ptr<sqlite3,
-      decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
+  std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*>
+      parser_memory_db_handle_;
   std::string parser_memory_db_path_;
   std::string parser_file_db_path_;
+  std::string locale_;
+  bool released_ = true;
+  std::unordered_map<std::string, std::vector<std::shared_ptr<package_x>>>
+      pkg_map_;
+  std::unordered_map<std::string, std::vector<std::shared_ptr<package_x>>>
+      old_pkg_map_;
+  std::unordered_map<std::string, std::vector<std::shared_ptr<application_x>>>
+      app_map_;
+  std::unordered_map<std::string, std::vector<std::shared_ptr<application_x>>>
+      old_app_map_;
 };
 
 }  // namespace database
diff --git a/src/server/database/pkg_get_cache_db_handler.cc b/src/server/database/pkg_get_cache_db_handler.cc
new file mode 100644 (file)
index 0000000..ef2bd6d
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "pkg_get_cache_db_handler.hh"
+
+#include <shared_mutex>
+#include <vector>
+
+#include "utils/logging.hh"
+
+#include "db_handle_provider.hh"
+#include "pkgmgrinfo_debug.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+PkgGetCacheDBHandler::PkgGetCacheDBHandler(uid_t uid, int pid)
+    : PkgGetDBHandler(uid, pid) {}
+
+int PkgGetCacheDBHandler::Execute() {
+  std::shared_lock<std::shared_timed_mutex> s(lock_);
+  SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+  SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+  bool write =
+      GetOpType() == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE;
+
+  std::vector<std::pair<sqlite3*, uid_t>> conn_list;
+  if (!Connect())
+    return PMINFO_R_ERROR;
+
+  conn_list = GetConnection();
+
+  int ret = PMINFO_R_OK;
+  std::string package;
+
+  for (auto* it = filter_->list; it != nullptr; it = g_slist_next(it)) {
+    auto node = reinterpret_cast<pkgmgrinfo_node_x*>(it->data);
+    if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_ID) {
+      package = node->value;
+      break;
+    }
+  }
+
+  std::vector<std::shared_ptr<package_x>> pkg_list;
+  for (auto& conn : conn_list) {
+    ret = DBHandleProvider::GetInst(conn.second)
+              .UpdateCache(conn.first, GetPID(), uid_, write, GetLocale());
+    if (ret != PMINFO_R_OK) {
+      LOG(ERROR) << "Failed to update pkginfo cache : " << ret;
+      break;
+    }
+
+    pkg_list = DBHandleProvider::GetInst(conn.second)
+                        .GetPackages(GetPID(), write, filter_, package);
+
+    handle_list_.reserve(pkg_list.size() + handle_list_.size());
+    std::move(std::begin(pkg_list), std::end(pkg_list),
+              std::back_inserter(handle_list_));
+  }
+
+  if (handle_list_.empty())
+    return PMINFO_R_ENOENT;
+
+  return ret;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/database/pkg_get_cache_db_handler.hh b/src/server/database/pkg_get_cache_db_handler.hh
new file mode 100644 (file)
index 0000000..56200fa
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PKG_GET_CACHE_DB_HANDLER_HH_
+#define PKG_GET_CACHE_DB_HANDLER_HH_
+
+#include <sys/types.h>
+
+#include <vector>
+
+#include "pkg_get_db_handler.hh"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API PkgGetCacheDBHandler : public PkgGetDBHandler {
+ public:
+  PkgGetCacheDBHandler(uid_t uid, int pid);
+  int Execute() override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PKG_GET_CACHE_DB_HANDLER_HH_
index c151983..8a1043d 100644 (file)
 #include <shared_mutex>
 #include <vector>
 
-#include "utils/logging.hh"
-
 #include "pkgmgrinfo_debug.h"
 #include "pkgmgrinfo_internal.h"
+#include "utils/logging.hh"
 
 namespace {
 
 gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
-  package_x* appinfo = static_cast<package_x*>(value);
-  std::vector<package_x*>* app_list =
-      static_cast<std::vector<package_x*>*>(user_data);
-  app_list->emplace_back(appinfo);
+  package_x* info = static_cast<package_x*>(value);
+  std::vector<std::shared_ptr<package_x>>* app_list =
+      static_cast<std::vector<std::shared_ptr<package_x>>*>(user_data);
+  app_list->emplace_back(info, pkgmgrinfo_basic_free_package);
 
   return true;
 }
 
-void __free_packages(gpointer data) {
-  pkgmgrinfo_basic_free_package(reinterpret_cast<package_x*>(data));
-}
-
 }  // namespace
 
 namespace pkgmgr_server {
@@ -49,7 +44,7 @@ PkgGetDBHandler::PkgGetDBHandler(uid_t uid, int pid)
 
 PkgGetDBHandler::~PkgGetDBHandler() {}
 
-std::vector<package_x*> PkgGetDBHandler::GetPkgHandle() {
+std::vector<std::shared_ptr<package_x>> PkgGetDBHandler::GetPkgHandle() {
   return std::move(handle_list_);
 }
 
@@ -66,13 +61,13 @@ int PkgGetDBHandler::Execute() {
     return PMINFO_R_ERROR;
   }
 
-  GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
-      NULL, __free_packages);
+  GHashTable* list =
+      g_hash_table_new_full(g_str_hash, g_str_equal, nullptr, nullptr);
   std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
   int ret = PMINFO_R_OK;
   for (auto& conn : conn_list) {
     ret = pkginfo_internal_filter_get_list(conn.first, filter_, conn.second,
-                                            GetLocale().c_str(), list);
+                                           GetLocale().c_str(), list);
     if (ret == PMINFO_R_ERROR) {
       LOG(ERROR) << "Failed to pkginfo_internal_filter_get_list : " << ret;
       break;
index 89adcf5..bc04570 100644 (file)
@@ -36,13 +36,13 @@ class EXPORT_API PkgGetDBHandler : public AbstractDBHandler {
  public:
   PkgGetDBHandler(uid_t uid, int pid);
   ~PkgGetDBHandler();
-  std::vector<package_x*> GetPkgHandle();
+  std::vector<std::shared_ptr<package_x>> GetPkgHandle();
   void SetFilter(pkgmgrinfo_filter_x* filter);
-  int Execute() override;
+  virtual int Execute();
 
- private:
+ protected:
   pkgmgrinfo_filter_x* filter_ = nullptr;
-  std::vector<package_x*> handle_list_;
+  std::vector<std::shared_ptr<package_x>> handle_list_;
   uid_t uid_;
 };
 
@@ -50,4 +50,3 @@ class EXPORT_API PkgGetDBHandler : public AbstractDBHandler {
 }  // namespace pkgmgr_server
 
 #endif  // PKG_GET_DB_HANDLER_HH_
-
diff --git a/src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..bf7619f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "app_disable_app_filter_checker.hh"
+
+#include <string.h>
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool AppDisableAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                             application_x* info) {
+  return (node->value != nullptr && info->is_disabled != nullptr &&
+          strcasecmp(node->value, info->is_disabled) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/app_disable_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..dae22bf
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APP_DISABLE_APP_FILTER_CHECKER_HH_
+#define APP_DISABLE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class AppDisableAppFilterChecker: public IAppFilterChecker {
+ public:
+  AppDisableAppFilterChecker() = default;
+  ~AppDisableAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // APP_DISABLE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/appid_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/appid_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..98b7b89
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "appid_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool AppIdAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                        application_x* info) {
+  return (node->value != nullptr && info->appid != nullptr &&
+          strcmp(node->value, info->appid) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/appid_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/appid_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..83d0ada
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APPID_APP_FILTER_CHECKER_HH_
+#define APPID_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class AppIdAppFilterChecker: public IAppFilterChecker {
+ public:
+  AppIdAppFilterChecker() = default;
+  ~AppIdAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // APPID_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/category_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/category_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..c84737a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include "category_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool CategoryAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                           application_x* info) {
+  for (auto* it = info->category; it != nullptr; it = g_list_next(it)) {
+    char* value = reinterpret_cast<char*>(it->data);
+    if (value != nullptr && strcmp(value, node->value) == 0) return true;
+  }
+
+  return false;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/category_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/category_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..155b5a3
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CATEGORY_APP_FILTER_CHECKER_HH_
+#define CATEGORY_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class CategoryAppFilterChecker: public IAppFilterChecker {
+ public:
+  CategoryAppFilterChecker() = default;
+  ~CategoryAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // CATEGORY_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/component_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/component_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..9352fbd
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "component_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool ComponentAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                           application_x* info) {
+  return (node->value != nullptr && info->component != nullptr &&
+          strcmp(node->value, info->component) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/component_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/component_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..80ac0c7
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMPONENT_APP_FILTER_CHECKER_HH_
+#define COMPONENT_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class ComponentAppFilterChecker: public IAppFilterChecker {
+ public:
+  ComponentAppFilterChecker() = default;
+  ~ComponentAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // COMPONENT_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/default_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/default_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..16b74ed
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "default_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool DefaultAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                          application_x* info) {
+  return true;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/default_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/default_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..490273a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DEFAULT_APP_FILTER_CHECKER_HH_
+#define DEFAULT_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class DefaultAppFilterChecker: public IAppFilterChecker {
+ public:
+  DefaultAppFilterChecker() = default;
+  ~DefaultAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // DEFAULT_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/exec_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/exec_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..184d960
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "exec_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool ExecAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                       application_x* info) {
+  return (node->value != nullptr && info->exec != nullptr &&
+          strcmp(node->value, info->exec) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/exec_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/exec_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..ae4593d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef EXEC_APP_FILTER_CHECKER_HH_
+#define EXEC_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class ExecAppFilterChecker: public IAppFilterChecker {
+ public:
+  ExecAppFilterChecker() = default;
+  ~ExecAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // EXEC_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..dfdcdbf
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nodisplay_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool NoDisplayAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            application_x* info) {
+  return (node->value != nullptr && info->nodisplay != nullptr &&
+          strcasecmp(node->value, info->nodisplay) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/nodisplay_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..ee17527
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NODISPLAY_DISABLE_APP_FILTER_CHECKER_HH_
+#define NODISPLAY_DISABLE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class NoDisplayAppFilterChecker: public IAppFilterChecker {
+ public:
+  NoDisplayAppFilterChecker() = default;
+  ~NoDisplayAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // NODISPLAY_DISABLE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/operation_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/operation_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..289188a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "operation_app_filter_checker.hh"
+
+#include <glib.h>
+
+namespace pkgmgr_server {
+namespace database {
+
+bool OperationAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            application_x* info) {
+  for (auto* it = info->appcontrol; it != nullptr; it = g_list_next(it)) {
+    char* value = reinterpret_cast<appcontrol_x*>(it->data)->operation;
+    if (value != nullptr && strcmp(value, node->value) == 0)
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/operation_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/operation_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..0c8f9f1
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OPERATION_APP_FILTER_CHECKER_HH_
+#define OPERATION_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class OperationAppFilterChecker: public IAppFilterChecker {
+ public:
+  OperationAppFilterChecker() = default;
+  ~OperationAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // OPERATION_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..bd9d116
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "pkg_disable_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PkgDisableAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                             application_x* info) {
+  return (node->value != nullptr && strcasecmp(node->value, "false") == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/pkg_disable_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..7fd6902
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PKG_DISABLE_APP_FILTER_CHECKER_HH_
+#define PKG_DISABLE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PkgDisableAppFilterChecker: public IAppFilterChecker {
+ public:
+  PkgDisableAppFilterChecker() = default;
+  ~PkgDisableAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PKG_DISABLE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..08d2093
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "pkgid_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PkgIdAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            application_x* info) {
+  return (node->value != nullptr && info->package != nullptr &&
+          strcmp(node->value, info->package) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/pkgid_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..1f35348
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PKGID_APP_FILTER_CHECKER_HH_
+#define PKGID_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PkgIdAppFilterChecker: public IAppFilterChecker {
+ public:
+  PkgIdAppFilterChecker() = default;
+  ~PkgIdAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PKGID_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..916c8d6
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "privilege_app_filter_checker.hh"
+
+#include <glib.h>
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PrivilegeAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            application_x* info) {
+  for (auto* it = info->privileges; it != nullptr; it = g_list_next(it)) {
+    char* value = reinterpret_cast<privilege_x*>(it->data)->value;
+    if (value != nullptr && strcmp(value, node->value) == 0) return true;
+  }
+
+  return false;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/privilege_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..f946798
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PRIVILEGE_APP_FILTER_CHECKER_HH_
+#define PRIVILEGE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PrivilegeAppFilterChecker: public IAppFilterChecker {
+ public:
+  PrivilegeAppFilterChecker() = default;
+  ~PrivilegeAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PRIVILEGE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/storage_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/storage_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..e968bfb
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "storage_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool StorageAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                             application_x* info) {
+  return (node->value != nullptr && info->installed_storage != nullptr &&
+          strcasecmp(node->value, info->installed_storage) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/storage_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/storage_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..cd56240
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef STORAGE_APP_FILTER_CHECKER_HH_
+#define STORAGE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class StorageAppFilterChecker: public IAppFilterChecker {
+ public:
+  StorageAppFilterChecker() = default;
+  ~StorageAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // STORAGE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker/type_app_filter_checker.cc b/src/server/filter_checker/app_filter_checker/type_app_filter_checker.cc
new file mode 100644 (file)
index 0000000..76e5e2f
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "type_app_filter_checker.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool TypeAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            application_x* info) {
+  return (node->value != nullptr && info->type != nullptr &&
+          strcmp(node->value, info->type) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/app_filter_checker/type_app_filter_checker.hh b/src/server/filter_checker/app_filter_checker/type_app_filter_checker.hh
new file mode 100644 (file)
index 0000000..951d7dd
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TYPE_APP_FILTER_CHECKER_HH_
+#define TYPE_APP_FILTER_CHECKER_HH_
+
+#include "app_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class TypeAppFilterChecker: public IAppFilterChecker {
+ public:
+  TypeAppFilterChecker() = default;
+  ~TypeAppFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // TYPE_APP_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/app_filter_checker_base.hh b/src/server/filter_checker/app_filter_checker_base.hh
new file mode 100644 (file)
index 0000000..ae00f9d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APP_FILTER_CHECKER_BASE_HH_
+#define APP_FILTER_CHECKER_BASE_HH_
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class IAppFilterChecker {
+ public:
+  IAppFilterChecker() = default;
+  virtual ~IAppFilterChecker() = default;
+  virtual bool CheckFilter(pkgmgrinfo_node_x* node, application_x* info) = 0;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // APP_FILTER_CHECKER_BASE_HH_
diff --git a/src/server/filter_checker/filter_checker_list.hh b/src/server/filter_checker/filter_checker_list.hh
new file mode 100644 (file)
index 0000000..69c4b23
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FILTER_CHECKER_LIST_HH_
+#define FILTER_CHECKER_LIST_HH_
+
+#include "app_filter_checker/app_disable_app_filter_checker.hh"
+#include "app_filter_checker/appid_app_filter_checker.hh"
+#include "app_filter_checker/category_app_filter_checker.hh"
+#include "app_filter_checker/component_app_filter_checker.hh"
+#include "app_filter_checker/default_app_filter_checker.hh"
+#include "app_filter_checker/exec_app_filter_checker.hh"
+#include "app_filter_checker/nodisplay_app_filter_checker.hh"
+#include "app_filter_checker/operation_app_filter_checker.hh"
+#include "app_filter_checker/pkg_disable_app_filter_checker.hh"
+#include "app_filter_checker/pkgid_app_filter_checker.hh"
+#include "app_filter_checker/privilege_app_filter_checker.hh"
+#include "app_filter_checker/storage_app_filter_checker.hh"
+#include "app_filter_checker/type_app_filter_checker.hh"
+
+#include "pkg_filter_checker/check_storage_pkg_filter_checker.hh"
+#include "pkg_filter_checker/default_pkg_filter_checker.hh"
+#include "pkg_filter_checker/disable_pkg_filter_checker.hh"
+#include "pkg_filter_checker/pkgid_pkg_filter_checker.hh"
+#include "pkg_filter_checker/preload_pkg_filter_checker.hh"
+#include "pkg_filter_checker/privilege_pkg_filter_checker.hh"
+#include "pkg_filter_checker/removable_pkg_filter_checker.hh"
+#include "pkg_filter_checker/restype_pkg_filter_checker.hh"
+
+#endif  // FILTER_CHECKER_LIST_HH_
diff --git a/src/server/filter_checker/filter_checker_provider.cc b/src/server/filter_checker/filter_checker_provider.cc
new file mode 100644 (file)
index 0000000..268ba66
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "filter_checker_provider.hh"
+
+#include <memory>
+
+#include "filter_checker_list.hh"
+#include "pkgmgrinfo_debug.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+FilterCheckerProvider::FilterCheckerProvider() {
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_ID] =
+      std::make_unique<PkgIdPkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE] =
+      std::make_unique<PrivilegePkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE] =
+      std::make_unique<RemovablePkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD] =
+      std::make_unique<PreloadPkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE] =
+      std::make_unique<DisablePkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE] =
+      std::make_unique<ResTypePkgFilterChecker>();
+  pkg_checker_map_[E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE] =
+      std::make_unique<CheckStoragePkgFilterChecker>();
+
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_ID] =
+      std::make_unique<AppIdAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_COMPONENT] =
+      std::make_unique<ComponentAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_EXEC] =
+      std::make_unique<ExecAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_TYPE] =
+      std::make_unique<TypeAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_OPERATION] =
+      std::make_unique<OperationAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_CATEGORY] =
+      std::make_unique<CategoryAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_PACKAGE] =
+      std::make_unique<PkgIdAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE] =
+      std::make_unique<StorageAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_PRIVILEGE] =
+      std::make_unique<PrivilegeAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_NODISPLAY] =
+      std::make_unique<NoDisplayAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_APP_DISABLE] =
+      std::make_unique<AppDisableAppFilterChecker>();
+  app_checker_map_[E_PMINFO_APPINFO_PROP_PKG_DISABLE] =
+      std::make_unique<PkgDisableAppFilterChecker>();
+
+  default_pkg_checker = std::make_unique<DefaultPkgFilterChecker>();
+  default_app_checker = std::make_unique<DefaultAppFilterChecker>();
+}
+
+FilterCheckerProvider& FilterCheckerProvider::GetInst() {
+  static FilterCheckerProvider inst;
+  return inst;
+}
+
+IPkgFilterChecker* FilterCheckerProvider::GetPkgFilterChecker(int id) {
+  auto it = pkg_checker_map_.find(id);
+  if (it == pkg_checker_map_.end()) {
+    _LOGE("Invalid filter id %d", id);
+    return default_pkg_checker.get();
+  }
+  return it->second.get();
+}
+
+IAppFilterChecker* FilterCheckerProvider::GetAppFilterChecker(int id) {
+  auto it = app_checker_map_.find(id);
+  if (it == app_checker_map_.end()) {
+    _LOGE("Invalid filter id %d", id);
+    return default_app_checker.get();
+  }
+  return it->second.get();
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/filter_checker_provider.hh b/src/server/filter_checker/filter_checker_provider.hh
new file mode 100644 (file)
index 0000000..1bac79d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FILTER_CHECKER_FACTORY_HH_
+#define FILTER_CHECKER_FACTORY_HH_
+
+#include <memory>
+#include <unordered_map>
+
+#include "pkg_filter_checker_base.hh"
+#include "app_filter_checker_base.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+class FilterCheckerProvider {
+ public:
+  static FilterCheckerProvider& GetInst();
+  ~FilterCheckerProvider() = default;
+  IPkgFilterChecker* GetPkgFilterChecker(int id);
+  IAppFilterChecker* GetAppFilterChecker(int id);
+
+ private:
+  FilterCheckerProvider();
+  std::unordered_map<int, std::unique_ptr<IPkgFilterChecker>> pkg_checker_map_;
+  std::unordered_map<int, std::unique_ptr<IAppFilterChecker>> app_checker_map_;
+
+  std::unique_ptr<IPkgFilterChecker> default_pkg_checker;
+  std::unique_ptr<IAppFilterChecker> default_app_checker;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // FILTER_CHECKER_BASE_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..5a37fda
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "check_storage_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool CheckStoragePkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                          package_x* info) {
+  return (node->value == nullptr || strcasecmp(node->value, "true") != 0 ||
+      __pkginfo_check_installed_storage(info) == PMINFO_R_OK);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/check_storage_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..5a4116f
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CHECK_STORAGE_PKG_FILTER_CHECKER_HH_
+#define CHECK_STORAGE_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class CheckStoragePkgFilterChecker : public IPkgFilterChecker {
+ public:
+  CheckStoragePkgFilterChecker() = default;
+  ~CheckStoragePkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // CHECK_STORAGE_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..15ded7f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "default_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool DefaultPkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                          package_x* info) {
+  return true;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/default_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..dbd88ff
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DEFAULT_PKG_FILTER_CHECKER_HH_
+#define DEFAULT_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class DefaultPkgFilterChecker: public IPkgFilterChecker {
+ public:
+  DefaultPkgFilterChecker() = default;
+  ~DefaultPkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // DEFAULT_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..ccd9d4a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "disable_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool DisablePkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                        package_x* info) {
+  return (node->value != nullptr && info->is_disabled != nullptr &&
+          strcasecmp(node->value, info->is_disabled) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/disable_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..d848eca
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DISABLE_PKG_FILTER_CHECKER_HH_
+#define DISABLE_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class DisablePkgFilterChecker: public IPkgFilterChecker {
+ public:
+  DisablePkgFilterChecker() = default;
+  ~DisablePkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // DISABLE_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..086ca51
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "pkgid_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PkgIdPkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                        package_x* info) {
+  return (node->value != nullptr && info->package != nullptr &&
+          strcmp(node->value, info->package) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/pkgid_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..4fc3560
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PKGID_PKG_FILTER_CHECKER_HH_
+#define PKGID_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PkgIdPkgFilterChecker: public IPkgFilterChecker {
+ public:
+  PkgIdPkgFilterChecker() = default;
+  ~PkgIdPkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PKGID_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..3019581
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "preload_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PreloadPkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                        package_x* info) {
+  return (node->value != nullptr && info->preload != nullptr &&
+          strcasecmp(node->value, info->preload) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/preload_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..c8dab32
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PRELOAD_PKG_FILTER_CHECKER_HH_
+#define PRELOAD_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PreloadPkgFilterChecker: public IPkgFilterChecker {
+ public:
+  PreloadPkgFilterChecker() = default;
+  ~PreloadPkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PRELOAD_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..55b77cb
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "privilege_pkg_filter_checker.hh"
+
+#include <glib.h>
+
+namespace pkgmgr_server {
+namespace database {
+
+bool PrivilegePkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                            package_x* info) {
+  for (auto* it = info->privileges; it != nullptr; it = g_list_next(it)) {
+    char* value = reinterpret_cast<privilege_x*>(it->data)->value;
+    if (value != nullptr && strcmp(value, node->value) == 0)
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/privilege_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..8ef6823
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PRIVILEGE_PKG_FILTER_CHECKER_HH_
+#define PRIVILEGE_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class PrivilegePkgFilterChecker: public IPkgFilterChecker {
+ public:
+  PrivilegePkgFilterChecker() = default;
+  ~PrivilegePkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PRIVILEGE_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..f995105
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "removable_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool RemovablePkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                        package_x* info) {
+  return (node->value != nullptr && info->removable != nullptr &&
+          strcasecmp(node->value, info->removable) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/removable_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..dda5176
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef REMOVABLE_PKG_FILTER_CHECKER_HH_
+#define REMOVABLE_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class RemovablePkgFilterChecker: public IPkgFilterChecker {
+ public:
+  RemovablePkgFilterChecker() = default;
+  ~RemovablePkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // REMOVABLE_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.cc b/src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.cc
new file mode 100644 (file)
index 0000000..f1a5861
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "restype_pkg_filter_checker.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+bool ResTypePkgFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
+                                          package_x* info) {
+  return (info->removable == nullptr || info->removable[0] == '\0' ||
+          strcasecmp(node->value, info->removable) == 0);
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.hh b/src/server/filter_checker/pkg_filter_checker/restype_pkg_filter_checker.hh
new file mode 100644 (file)
index 0000000..bbd461f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RESTYPE_PKG_FILTER_CHECKER_HH_
+#define RESTYPE_PKG_FILTER_CHECKER_HH_
+
+#include "pkg_filter_checker_base.hh"
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class ResTypePkgFilterChecker: public IPkgFilterChecker {
+ public:
+  ResTypePkgFilterChecker() = default;
+  ~ResTypePkgFilterChecker() = default;
+  bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) override;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // RESTYPE_PKG_FILTER_CHECKER_HH_
diff --git a/src/server/filter_checker/pkg_filter_checker_base.hh b/src/server/filter_checker/pkg_filter_checker_base.hh
new file mode 100644 (file)
index 0000000..13d3d09
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PKG_FILTER_CHECKER_BASE_HH_
+#define PKG_FILTER_CHECKER_BASE_HH_
+
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
+
+namespace pkgmgr_server {
+namespace database {
+
+class IPkgFilterChecker {
+ public:
+  IPkgFilterChecker() = default;
+  virtual ~IPkgFilterChecker() = default;
+  virtual bool CheckFilter(pkgmgrinfo_node_x* node, package_x* info) = 0;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // PKG_FILTER_CHECKER_BASE_HH_
index 8431e98..01d0550 100644 (file)
@@ -77,9 +77,15 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        char *condition = NULL;
        GSList *list = NULL;
 
-       if (filter == NULL)
+       if (!filter)
                return PMINFO_R_OK;
 
+       if (g_slist_length(filter->list) == 0) {
+               joined = E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO |
+                       E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO |
+                       E_PMINFO_PKGINFO_JOIN_RES_INFO;
+       }
+
        snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
        for (list = filter->list; list; list = list->next) {
                joined |= __get_filter_condition(list->data, uid, &condition,
@@ -478,7 +484,7 @@ static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
                "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
                "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
                "pi.package_support_disable, pi.package_tep_name, "
-               "pi.package_zip_mount_file, pi.package_support_mode";
+               "pi.package_zip_mount_file, pi.package_support_mode, pi.package_disable";
        static const char query_author[] =
                ", pi.author_name, pi.author_email, pi.author_href";
        static const char query_label[] =
@@ -609,6 +615,7 @@ static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
                        _save_column_str(stmt, idx++, &info->tep_name);
                        _save_column_str(stmt, idx++, &info->zip_mount_file);
                        _save_column_str(stmt, idx++, &info->support_mode);
+                       _save_column_str(stmt, idx++, &info->is_disabled);
                }
 
                info->for_all_users =
index 73bf794..2f5cc1d 100644 (file)
@@ -6,12 +6,12 @@
 
 #include <string>
 
+#include "appinfo_cache_db_handler.hh"
 #include "appinfo_db_handler.hh"
 #include "filter_parcelable.hh"
 #include "parcelable_factory.hh"
-#include "utils/logging.hh"
-
 #include "pkgmgrinfo_debug.h"
+#include "utils/logging.hh"
 
 namespace pcp = pkgmgr_common::parcel;
 namespace psd = pkgmgr_server::database;
@@ -19,6 +19,10 @@ namespace psd = pkgmgr_server::database;
 namespace pkgmgr_server {
 namespace request_handler {
 
+GetAppinfoRequestHandler::GetAppinfoRequestHandler(bool cache)
+    : cache_(cache) {
+}
+
 bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size,
                                              const std::string& locale) {
   auto abstract_parcel =
@@ -28,7 +32,7 @@ bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size,
       abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
     LOG(ERROR) << "Invalid parcel or type";
     result_ = std::make_shared<pcp::AppInfoParcelable>(
-        PMINFO_R_ERROR, std::vector<application_x*>{});
+        PMINFO_R_ERROR, std::vector<std::shared_ptr<application_x>>{});
     return false;
   }
 
@@ -36,17 +40,23 @@ bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size,
   if (parcel == nullptr) {
     LOG(ERROR) << "Parcel is empty";
     result_ = std::make_shared<pcp::AppInfoParcelable>(
-        PMINFO_R_ERROR, std::vector<application_x*>{});
+        PMINFO_R_ERROR, std::vector<std::shared_ptr<application_x>>{});
     return false;
   }
 
-  psd::AppInfoDBHandler db(parcel->GetUid(), GetPID());
-  db.SetLocale(locale);
-  db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
-  int ret = db.Execute();
+  psd::AppInfoDBHandler* db;
+  if (cache_)
+    db = new psd::AppInfoCacheDBHandler(parcel->GetUid(), GetPID());
+  else
+    db = new psd::AppInfoDBHandler(parcel->GetUid(), GetPID());
+
+  db->SetLocale(locale);
+  db->SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
+  int ret = db->Execute();
 
-  result_ = std::make_shared<pcp::AppInfoParcelable>(ret, db.GetAppHandle());
+  result_ = std::make_shared<pcp::AppInfoParcelable>(ret, db->GetAppHandle());
 
+  delete db;
   return true;
 }
 
index 8fac2d9..71c574c 100644 (file)
@@ -19,13 +19,15 @@ namespace request_handler {
 
 class EXPORT_API GetAppinfoRequestHandler : public AbstractRequestHandler {
  public:
-  bool HandleRequest(unsigned char* data, int size,
-      const std::string& locale) override;
+  explicit GetAppinfoRequestHandler(bool cache = false);
+  bool HandleRequest(unsigned char *data, int size,
+      const std::string &locale) override;
 
   std::vector<uint8_t> ExtractResult() override;
 
  private:
   std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> result_;
+  bool cache_;
 };
 
 }  // namespace request_handler
index f198912..1d54517 100644 (file)
@@ -8,11 +8,10 @@
 
 #include "filter_parcelable.hh"
 #include "parcelable_factory.hh"
+#include "pkg_get_cache_db_handler.hh"
 #include "pkg_get_db_handler.hh"
-#include "utils/logging.hh"
-
 #include "pkgmgrinfo_debug.h"
-
+#include "utils/logging.hh"
 
 namespace pcp = pkgmgr_common::parcel;
 namespace psd = pkgmgr_server::database;
@@ -20,8 +19,12 @@ namespace psd = pkgmgr_server::database;
 namespace pkgmgr_server {
 namespace request_handler {
 
+GetPkginfoRequestHandler::GetPkginfoRequestHandler(bool cache)
+    : cache_(cache) {
+}
+
 bool GetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
-                                             const std::string& locale) {
+    const std::string& locale) {
   auto abstract_parcel =
       pcp::ParcelableFactory::GetInst().CreateParcel(data, size);
 
@@ -29,7 +32,7 @@ bool GetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
       abstract_parcel->GetType() != pcp::ParcelableType::Filter) {
     LOG(ERROR) << "Invalid parcel or type";
     result_ = std::make_shared<pcp::PkgInfoParcelable>(
-        PMINFO_R_ERROR, std::vector<package_x*>{});
+        PMINFO_R_ERROR, std::vector<std::shared_ptr<package_x>>{});
     return false;
   }
 
@@ -37,17 +40,23 @@ bool GetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
   if (parcel == nullptr) {
     LOG(ERROR) << "Parcel is empty";
     result_ = std::make_shared<pcp::PkgInfoParcelable>(
-        PMINFO_R_ERROR, std::vector<package_x*>{});
+        PMINFO_R_ERROR, std::vector<std::shared_ptr<package_x>>{});
     return false;
   }
 
-  psd::PkgGetDBHandler db(parcel->GetUid(), GetPID());
-  db.SetLocale(locale);
-  db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
-  int ret = db.Execute();
+  psd::PkgGetDBHandler* db;
+  if (cache_)
+    db = new psd::PkgGetCacheDBHandler(parcel->GetUid(), GetPID());
+  else
+    db = new psd::PkgGetDBHandler(parcel->GetUid(), GetPID());
+
+  db->SetLocale(locale);
+  db->SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
+  int ret = db->Execute();
 
-  result_ = std::make_shared<pcp::PkgInfoParcelable>(ret, db.GetPkgHandle());
+  result_ = std::make_shared<pcp::PkgInfoParcelable>(ret, db->GetPkgHandle());
 
+  delete db;
   return true;
 }
 
index 0bf022f..c567326 100644 (file)
@@ -19,6 +19,7 @@ namespace request_handler {
 
 class EXPORT_API GetPkginfoRequestHandler : public AbstractRequestHandler {
  public:
+  explicit GetPkginfoRequestHandler(bool cache = false);
   bool HandleRequest(unsigned char* data, int size,
       const std::string& locale) override;
 
@@ -26,6 +27,7 @@ class EXPORT_API GetPkginfoRequestHandler : public AbstractRequestHandler {
 
  private:
   std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> result_;
+  bool cache_;
 };
 
 }  // namespace request_handler
index d530b5d..d7a8f8b 100644 (file)
@@ -49,7 +49,7 @@ bool SetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
   int ret = PM_PARSER_R_ERROR;
 
   for (auto& i : parcel->GetPkgInfo()) {
-    db.SetPkgInfo(i);
+    db.SetPkgInfo(i.get());
     ret = db.Execute();
     if (ret != PM_PARSER_R_OK) {
       LOG(ERROR) << "Failed to set pkginfo";
@@ -57,6 +57,9 @@ bool SetPkginfoRequestHandler::HandleRequest(unsigned char* data, int size,
     }
   }
 
+  for (auto& i : parcel->GetPkgInfo())
+    pkgmgrinfo_basic_free_package(i.get());
+
   result_ = std::make_shared<pcp::ResultParcelable>(
       ret, std::vector<pcp::StrArgs>{});
 
index 513c175..84c9f4a 100644 (file)
@@ -19,3 +19,17 @@ inline void _save_column_str(sqlite3_stmt *stmt, int idx, char **str)
        if (val)
                *str = strdup(val);
 }
+
+void _save_column_bool(sqlite3_stmt *stmt, int idx, bool *bool_value)
+{
+       const char *val;
+
+       val = (const char *)sqlite3_column_text(stmt, idx);
+       if (!val)
+               return;
+
+       if (strcasecmp(val, "true") == 0)
+               *bool_value = true;
+       else if (strcasecmp(val, "false") == 0)
+               *bool_value = false;
+}
index 5ec2350..28680c6 100644 (file)
@@ -74,9 +74,9 @@ void WorkerThread::Run() {
   std::unique_ptr<request_handler::AbstractRequestHandler>
       handler[pkgmgr_common::ReqType::MAX];
   handler[pkgmgr_common::ReqType::GET_PKG_INFO].reset(
-      new request_handler::GetPkginfoRequestHandler());
+      new request_handler::GetPkginfoRequestHandler(true));
   handler[pkgmgr_common::ReqType::GET_APP_INFO].reset(
-      new request_handler::GetAppinfoRequestHandler());
+      new request_handler::GetAppinfoRequestHandler(true));
   handler[pkgmgr_common::ReqType::SET_PKG_INFO].reset(
       new request_handler::SetPkginfoRequestHandler());
   handler[pkgmgr_common::ReqType::SET_CERT_INFO].reset(
@@ -175,6 +175,9 @@ gboolean WorkerThread::TrimMemory(void* data) {
     database::DBHandleProvider::
         GetInst(getuid()).UnsetMemoryMode(getpid());
 
+  database::DBHandleProvider::
+        GetInst(getuid()).TrimCache();
+
   return false;
 }
 
index 7f31bbf..b90d336 100644 (file)
@@ -388,23 +388,25 @@ bool IsEqualApplication(application_x* applicationA,
 }
 
 bool IsEqualApplicationsStructure(
-    const std::vector<application_x*>& applicationsA,
-    const std::vector<application_x*>& applicationsB) {
+    const std::vector<std::shared_ptr<application_x>>& applicationsA,
+    const std::vector<std::shared_ptr<application_x>>& applicationsB) {
 
   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
-    if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
+    if (!IsEqualApplication(applicationsA[i].get(), applicationsB[i].get()))
       return false;
-    if (!IsEqualApplicationExtraInfo(applicationsA[i], applicationsB[i]))
+    if (!IsEqualApplicationExtraInfo(applicationsA[i].get(),
+        applicationsB[i].get()))
       return false;
   }
 
   return true;
 }
 
-bool IsEqualApplicationsInfo(const std::vector<application_x*>& applicationsA,
-    const std::vector<application_x*>& applicationsB) {
+bool IsEqualApplicationsInfo(
+    const std::vector<std::shared_ptr<application_x>>& applicationsA,
+    const std::vector<std::shared_ptr<application_x>>& applicationsB) {
   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
-    if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
+    if (!IsEqualApplication(applicationsA[i].get(), applicationsB[i].get()))
       return false;
   }
 
@@ -747,28 +749,30 @@ bool IsEqualPackage(package_x* packageA, package_x* packageB) {
   return true;
 }
 
-bool IsEqualPackagesStructure(const std::vector<package_x*>& packagesA,
-    const std::vector<package_x*>&packagesB) {
+bool IsEqualPackagesStructure(
+    const std::vector<std::shared_ptr<package_x>>& packagesA,
+    const std::vector<std::shared_ptr<package_x>>& packagesB) {
   if (packagesA.size() != packagesB.size())
     return false;
 
   for (unsigned int i = 0; i < packagesA.size(); ++i) {
-    if (!IsEqualPackage(packagesA[i], packagesB[i]))
+    if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
       return false;
-    if (!IsEqualPackageExtraInfo(packagesA[i], packagesB[i]))
+    if (!IsEqualPackageExtraInfo(packagesA[i].get(), packagesB[i].get()))
       return false;
   }
 
   return true;
 }
 
-bool IsEqualPackagesInfo(const std::vector<package_x*>& packagesA,
-    const std::vector<package_x*>&packagesB) {
+bool IsEqualPackagesInfo(
+    const std::vector<std::shared_ptr<package_x>>& packagesA,
+    const std::vector<std::shared_ptr<package_x>>& packagesB) {
   if (packagesA.size() != packagesB.size())
     return false;
 
   for (unsigned int i = 0; i < packagesA.size(); ++i) {
-    if (!IsEqualPackage(packagesA[i], packagesB[i]))
+    if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
       return false;
   }
 
index 6acfee2..efb59d3 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include <string>
 #include <vector>
+#include <memory>
 
 #include "pkgmgrinfo_basic.h"
 #include "pkgmgrinfo_private.h"
 
 application_x *GetTestApplication(std::string appid);
 
-bool IsEqualApplicationsStructure(const std::vector<application_x*>& applicationsA,
-    const std::vector<application_x*>& applicationsB);
+bool IsEqualApplicationsStructure(const std::vector<std::shared_ptr<application_x>>& applicationsA,
+    const std::vector<std::shared_ptr<application_x>>& applicationsB);
 
-bool IsEqualApplicationsInfo(const std::vector<application_x*>& applicationsA,
-    const std::vector<application_x*>& applicationsB);
+bool IsEqualApplicationsInfo(const std::vector<std::shared_ptr<application_x>>& applicationsA,
+    const std::vector<std::shared_ptr<application_x>>& applicationsB);
 
 package_x *GetTestPackage(std::string pkgid);
 
 package_x* GetUpdatedTestPackage(std::string pkgid);
 
-bool IsEqualPackagesStructure(const std::vector<package_x*>&packagesA,
-    const std::vector<package_x*>&packagesB);
+bool IsEqualPackagesStructure(const std::vector<std::shared_ptr<package_x>>& packagesA,
+    const std::vector<std::shared_ptr<package_x>>&packagesB);
 
-bool IsEqualPackagesInfo(const std::vector<package_x*>&packagesA,
-    const std::vector<package_x*>&packagesB);
+bool IsEqualPackagesInfo(const std::vector<std::shared_ptr<package_x>>& packagesA,
+    const std::vector<std::shared_ptr<package_x>>& packagesB);
 
 pkgmgrinfo_filter_x *GetTestFilter();
 
index f5472d1..62dbeab 100644 (file)
@@ -105,7 +105,7 @@ TEST_F(ParcelTest, AbstractParcelableTest) {
 
 TEST_F(ParcelTest, AppInfoParcelable) {
   tizen_base::Parcel parcel;
-  std::vector<application_x *> origin_applications;
+  std::vector<std::shared_ptr<application_x>> origin_applications;
 
   origin_applications.emplace_back(GetTestApplication("test_appid1"));
   origin_applications.emplace_back(GetTestApplication("test_appid2"));
@@ -120,7 +120,7 @@ TEST_F(ParcelTest, AppInfoParcelable) {
 
 TEST_F(ParcelTest, PkgInfoParcelable) {
   tizen_base::Parcel parcel;
-  std::vector<package_x *> origin_packages;
+  std::vector<std::shared_ptr<package_x>> origin_packages;
 
   origin_packages.emplace_back(GetTestPackage("test_pkgid1"));
   origin_packages.emplace_back(GetTestPackage("test_pkgid2"));
index ce68b2e..7524bc1 100644 (file)
@@ -239,7 +239,7 @@ TEST_F(ParserDBHandlerTest, PkgGetDBHandlerTest) {
   ASSERT_EQ(lpkginfo_list.size(), 1);
 
   auto test_pkginfo = GetTestPackage(pkgid);
-  std::vector<package_x*> rpkginfo_list;
+  std::vector<std::shared_ptr<package_x>> rpkginfo_list;
   rpkginfo_list.emplace_back(test_pkginfo);
 
   ASSERT_EQ(IsEqualPackagesInfo(lpkginfo_list, rpkginfo_list), true);
@@ -283,7 +283,7 @@ TEST_F(ParserDBHandlerTest, AppInfoDBHandlerTest) {
   ASSERT_EQ(lappinfo_list.size(), 1);
 
   auto test_appinfo = GetTestApplication(appid);
-  std::vector<application_x*> rappinfo_list;
+  std::vector<std::shared_ptr<application_x>> rappinfo_list;
   rappinfo_list.emplace_back(test_appinfo);
 
   ASSERT_EQ(IsEqualApplicationsInfo(lappinfo_list, rappinfo_list), true);