+void DBHandleProvider::RegisterPendingPackageInfo(
+ package_x* info, pid_t pid) {
+ if (!info || !info->package)
+ return;
+
+ pending_pkg_[pid].emplace(info->package);
+}
+
+bool DBHandleProvider::UpdatePendingPackageInfo(sqlite3* db,
+ pid_t pid, uid_t uid, const std::string& locale) {
+ auto it = pending_pkg_.find(pid);
+ if (it == pending_pkg_.end()) {
+ LOG(WARNING) << "There is no package that is pending by the pid : " << pid;
+ return true;
+ }
+
+ GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+
+ pkgmgrinfo_filter_x tmp_filter = { 0, };
+ pkgmgrinfo_node_x node = {
+ .prop = E_PMINFO_PKGINFO_PROP_PACKAGE_ID
+ };
+ tmp_filter.cache_flag = true;
+ tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
+ for (const auto& pkg : it->second) {
+ pkg_map_.erase(pkg);
+ for (auto& appid : pkg_app_map_[pkg]) {
+ app_map_.erase(appid);
+ }
+
+ pkg_app_map_.erase(pkg);
+ node.value = const_cast<char*>(pkg.c_str());
+ pkginfo_internal_filter_get_list(db, &tmp_filter,
+ uid_, locale.c_str(), list);
+ }
+ g_slist_free(tmp_filter.list);
+
+ 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);
+ std::string pkgid = pkg->package;
+ AddPackage(std::move(pkgid), pkg);
+ }
+
+ g_hash_table_iter_init(&iter, list);
+ node.prop = E_PMINFO_APPINFO_PROP_APP_PACKAGE;
+ while (g_hash_table_iter_next(&iter, nullptr, &value)) {
+ auto* pkg = reinterpret_cast<package_x*>(value);
+ node.value = pkg->package;
+ std::vector<std::shared_ptr<application_x>> app_list;
+ pkgmgr_server::internal::appinfo_internal_filter_get_list(
+ db, &tmp_filter, uid_, uid, locale.c_str(), app_list);
+
+ for (auto& app : app_list) {
+ app->privileges = pkg->privileges;
+ std::string appid = app->appid;
+ AddApplication(std::move(appid), std::move(app));
+ }
+ }
+
+ g_hash_table_destroy(list);
+ pending_pkg_.erase(pid);
+ return true;
+}
+
+bool DBHandleProvider::UpdateCachePkg(sqlite3* db, uid_t uid,
+ const std::string& pkgid, const std::string& locale) {
+ GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == nullptr) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+
+ pkgmgrinfo_filter_x tmp_filter = { 0, };
+ pkgmgrinfo_node_x node = {
+ .prop = E_PMINFO_PKGINFO_PROP_PACKAGE_ID,
+ .value = const_cast<char*>(pkgid.c_str())
+ };
+ tmp_filter.cache_flag = true;
+ tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
+ pkginfo_internal_filter_get_list(db, &tmp_filter,
+ uid_, locale.c_str(), list);
+
+ 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);
+ std::string pkgid = pkg->package;
+ AddPackage(pkgid, pkg);
+
+ for (auto& appid : pkg_app_map_[pkgid]) {
+ app_map_.erase(appid);
+ }
+
+ pkg_app_map_.erase(pkgid);
+
+ std::vector<std::shared_ptr<application_x>> app_list;
+ node.prop = E_PMINFO_APPINFO_PROP_APP_PACKAGE;
+ node.value = const_cast<char*>(pkgid.c_str());
+
+ pkgmgr_server::internal::appinfo_internal_filter_get_list(
+ db, &tmp_filter, uid_, uid, locale.c_str(), app_list);
+
+ for (auto& app : app_list) {
+ app->privileges = pkg->privileges;
+ std::string appid = app->appid;
+ AddApplication(std::move(appid), std::move(app));
+ }
+ }
+
+ g_slist_free(tmp_filter.list);
+ return true;
+}
+
+bool DBHandleProvider::UpdateCacheApp(sqlite3* db, uid_t uid,
+ const std::string& appid, const std::string& locale) {
+ pkgmgrinfo_filter_x tmp_filter = { 0, };
+ pkgmgrinfo_node_x node = {
+ .prop = E_PMINFO_APPINFO_PROP_APP_ID,
+ .value = const_cast<char*>(appid.c_str())
+ };
+ tmp_filter.cache_flag = true;
+ tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
+
+ std::vector<std::shared_ptr<application_x>> app_list;
+ app_map_.erase(appid);
+ pkgmgr_server::internal::appinfo_internal_filter_get_list(db,
+ &tmp_filter, uid_, uid, locale.c_str(), app_list);
+ g_slist_free(tmp_filter.list);
+
+ for (auto& app : app_list) {
+ auto it = pkg_map_.find(app->package);
+ if (it == pkg_map_.end()) {
+ LOG(ERROR) << "Can not find package from pkg_map";
+ return false;
+ }
+
+ pkg_app_map_[app->package].erase(app->appid);
+ app->privileges = it->second->privileges;
+ std::string appid = app->appid;
+ AddApplication(std::move(appid), std::move(app));
+ }
+
+ return true;
+}
+
+bool DBHandleProvider::UpdateCacheAppByPkgid(sqlite3* db, uid_t uid,
+ const std::string& pkgid, const std::string& locale) {
+ auto it = pkg_map_.find(pkgid);
+ if (it == pkg_map_.end()) {
+ LOG(ERROR) << "Can not find package from pkg_map";
+ return false;
+ }
+
+ auto& pkg = it->second;
+ pkgmgrinfo_filter_x tmp_filter = { 0, };
+ pkgmgrinfo_node_x node = {
+ .prop = E_PMINFO_APPINFO_PROP_APP_PACKAGE,
+ .value = pkg->package
+ };
+
+ tmp_filter.cache_flag = true;
+ tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
+
+ std::vector<std::shared_ptr<application_x>> app_list;
+ pkgmgr_server::internal::appinfo_internal_filter_get_list(
+ db, &tmp_filter, uid_, uid, locale.c_str(), app_list);
+
+ for (auto& appid : pkg_app_map_[pkgid]) {
+ app_map_.erase(appid);
+ }
+ pkg_app_map_.erase(pkgid);
+
+ for (auto& app : app_list) {
+ app->privileges = pkg->privileges;
+ std::string appid = app->appid;
+ AddApplication(std::move(appid), std::move(app));
+ }
+
+ g_slist_free(tmp_filter.list);
+ return true;
+}
+