2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "manager/pkginfo_manager.h"
19 #include <sys/types.h>
26 #include "pkgmgrinfo_private.h"
29 #include "common/database/abstract_db_handler.hh"
30 #include "common/database/pkg_set_db_handler.hh"
31 #include "common/parcel/appinfo_parcelable.hh"
32 #include "common/parcel/filter_parcelable.hh"
33 #include "common/parcel/pkginfo_parcelable.hh"
34 #include "common/parcel/query_parcelable.hh"
35 #include "common/parcel/result_parcelable.hh"
37 #include "client/pkginfo_client.hh"
44 #define LOG_TAG "PKGMGR_INFO"
49 #define EXPORT_API __attribute__((visibility("default")))
51 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
52 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
53 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
54 new pkgmgr_common::parcel::FilterParcelable(uid,
55 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
57 pkgmgr_client::PkgInfoClient client(parcelable, uid,
58 pkgmgr_common::ReqType::GET_PKG_INFO);
59 if (!client.SendRequest())
60 return PMINFO_R_ERROR;
62 std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> return_parcel(
63 std::static_pointer_cast<pkgmgr_common::parcel::PkgInfoParcelable>(
64 client.GetResultParcel()));
66 tizen_base::Parcel parcel;
67 parcel.ReadParcelable(return_parcel.get());
69 auto result_list = return_parcel->GetPkgInfo();
70 // TODO: check noentry error has returned if size of result_list is 0
71 for (auto& pkginfo : result_list)
72 g_hash_table_insert(packages, (gpointer)pkginfo->package,
78 // TODO: Need to add target db uid to identify which database to be searched
79 extern "C" EXPORT_API int _appinfo_get_applications(uid_t db_uid, uid_t uid,
80 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
81 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
82 new pkgmgr_common::parcel::FilterParcelable(uid,
83 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
85 pkgmgr_client::PkgInfoClient client(parcelable, uid, pkgmgr_common::ReqType::GET_APP_INFO);
86 if (!client.SendRequest())
87 return PMINFO_R_ERROR;
89 std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> return_parcel(
90 std::static_pointer_cast<pkgmgr_common::parcel::AppInfoParcelable>(
91 client.GetResultParcel()));
93 tizen_base::Parcel parcel;
94 parcel.ReadParcelable(return_parcel.get());
95 auto result_list = return_parcel->GetAppInfo();
96 for (auto& appinfo : result_list)
97 g_hash_table_insert(packages, (gpointer)appinfo->appid,
103 extern "C" EXPORT_API char *_appinfo_get_localed_label(
104 const char *appid, const char *locale, uid_t uid) {
105 char *query = nullptr;
106 query = sqlite3_mprintf(
107 "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
108 "WHERE app_id=%Q AND app_locale=%Q),"
109 "(SELECT app_label FROM package_app_localized_info WHERE "
110 "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
111 if (query == nullptr) {
112 LOG(ERROR) << "Out of memory";
116 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
117 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
118 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
119 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
121 pkgmgr_client::PkgInfoClient client(parcelable, uid,
122 pkgmgr_common::ReqType::QUERY);
123 if (!client.SendRequest()) {
128 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
129 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
130 client.GetResultParcel()));
131 tizen_base::Parcel parcel;
132 parcel.ReadParcelable(return_parcel.get());
134 // result_list is vector of string vector
135 char *label = nullptr;
136 auto result_list = return_parcel->GetResult();
137 for (auto result : result_list) {
138 // result is string vector
139 // it only has one string or not.
140 if (result.front().empty() || result.front().length() == 0)
142 label = strdup(result.front().c_str());
143 if (label == nullptr) {
144 LOG(ERROR) << "Out of memory";
153 extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
154 const char *providerid, const char *type, uid_t uid,
155 char **appid, char **access) {
156 char *query = nullptr;
157 query = sqlite3_mprintf("SELECT app_id, access FROM "
158 "package_app_data_control WHERE "
159 "providerid=%Q AND type=%Q", providerid, type);
160 if (query == nullptr) {
161 LOG(ERROR) << "Out of memory";
162 return PMINFO_R_ERROR;
165 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
166 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
167 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
168 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
170 pkgmgr_client::PkgInfoClient client(parcelable, uid,
171 pkgmgr_common::ReqType::QUERY);
172 if (!client.SendRequest()) {
174 return PMINFO_R_ERROR;
177 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
178 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
179 client.GetResultParcel()));
180 tizen_base::Parcel parcel;
181 parcel.ReadParcelable(return_parcel.get());
183 // result_list is vector of string vector
184 auto result_list = return_parcel->GetResult();
185 if (result_list.size() == 0)
186 return PMINFO_R_ENOENT;
187 for (auto result : result_list) {
188 if (result.size() != 2)
189 return PMINFO_R_ERROR;
190 if (result.front().empty() || result.front().size() == 0 ||
191 result.back().empty() || result.back().size() == 0)
192 return PMINFO_R_ERROR;
193 *appid = strdup(result.front().c_str());
194 *access = strdup(result.back().c_str());
195 if (*appid == nullptr || *access == nullptr) {
196 LOG(ERROR) << "Out of memory";
197 return PMINFO_R_ERROR;
204 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
205 const char *providerid, uid_t uid, char **appid) {
206 char *query = nullptr;
208 query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
209 "WHERE providerid=%Q", providerid);
210 if (query == nullptr) {
211 LOGE("Out of memory");
212 return PMINFO_R_ERROR;
214 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
215 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
216 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
217 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
219 pkgmgr_client::PkgInfoClient client(parcelable, uid,
220 pkgmgr_common::ReqType::QUERY);
221 if (!client.SendRequest()) {
223 return PMINFO_R_ERROR;
225 // TODO: deliver rawdata to reqhandler directly if server is not working
227 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
228 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
229 client.GetResultParcel()));
230 tizen_base::Parcel parcel;
231 parcel.ReadParcelable(return_parcel.get());
234 // result_list is vector of string vector
235 auto result_list = return_parcel->GetResult();
236 if (result_list.size() == 0)
237 return PMINFO_R_ENOENT;
238 for (auto result : result_list) {
239 if (result.size() != 1)
240 return PMINFO_R_ERROR;
241 if (result.front().empty() || result.front().size() == 0)
242 return PMINFO_R_ERROR;
243 *appid = strdup(result.front().c_str());
244 if (*appid == nullptr) {
245 LOG(ERROR) << "Out of memory";
246 return PMINFO_R_ERROR;
253 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
254 const char *providerid, const char *type, uid_t uid,
255 char **appid, char **trusted) {
256 char *query = nullptr;
257 query = sqlite3_mprintf(
258 "SELECT app_id, trusted FROM package_app_data_control "
259 "WHERE providerid=%Q AND type=%Q", providerid, type);
260 if (query == nullptr) {
261 LOGE("Out of memory");
262 return PMINFO_R_ERROR;
265 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
266 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
267 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
268 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
270 pkgmgr_client::PkgInfoClient client(parcelable, uid,
271 pkgmgr_common::ReqType::QUERY);
272 if (!client.SendRequest()) {
274 return PMINFO_R_ERROR;
276 // TODO: deliver rawdata to reqhandler directly if server is not working
278 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
279 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
280 client.GetResultParcel()));
281 tizen_base::Parcel parcel;
282 parcel.ReadParcelable(return_parcel.get());
284 // result_list is vector of string vector
285 auto result_list = return_parcel->GetResult();
286 if (result_list.size() == 0)
287 return PMINFO_R_ENOENT;
288 for (auto result : result_list) {
289 if (result.size() != 2)
290 return PMINFO_R_ERROR;
291 if (result.front().empty() || result.front().size() == 0 ||
292 result.back().empty() || result.back().size() == 0)
293 return PMINFO_R_ERROR;
294 *appid = strdup(result.front().c_str());
295 *trusted = strdup(result.back().c_str());
296 if (*appid == nullptr || *trusted == nullptr) {
297 LOG(ERROR) << "Out of memory";
298 return PMINFO_R_ERROR;
305 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
306 const char *providerid, const char *type, uid_t uid,
307 GList **privileges) {
308 char *query = nullptr;
309 query = sqlite3_mprintf(
310 "SELECT privilege FROM package_app_data_control_privilege "
311 "WHERE providerid=%Q AND type=%Q", providerid, type);
312 if (query == nullptr) {
313 LOGE("Out of memory");
314 return PMINFO_R_ERROR;
317 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
318 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
319 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
320 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
322 pkgmgr_client::PkgInfoClient client(parcelable, uid,
323 pkgmgr_common::ReqType::QUERY);
324 if (!client.SendRequest()) {
326 return PMINFO_R_ERROR;
328 // TODO: deliver rawdata to reqhandler directly if server is not working
330 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
331 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
332 client.GetResultParcel()));
333 tizen_base::Parcel parcel;
334 parcel.ReadParcelable(return_parcel.get());
336 // result_list is vector of string vector
337 auto result_list = return_parcel->GetResult();
338 if (result_list.size() == 0)
339 return PMINFO_R_ENOENT;
341 for (auto result : result_list) {
342 if (result.size() != 1)
343 return PMINFO_R_ERROR;
344 if (result.front().empty() || result.front().size() == 0)
345 return PMINFO_R_ERROR;
346 char *privilege = strdup(result.front().c_str());
347 if (privilege == nullptr) {
348 LOG(ERROR) << "Out of memory";
349 return PMINFO_R_ERROR;
351 *privileges = g_list_append(*privileges, privilege);
357 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
358 const char *appid, const char *operation, uid_t uid, GList **privileges) {
359 char *query = nullptr;
360 query = sqlite3_mprintf(
361 "SELECT app_control, privilege FROM package_app_app_control_privilege "
362 "WHERE app_id=%Q", appid);
363 if (query == nullptr) {
364 LOG(ERROR) << "Out of memory";
365 return PMINFO_R_ERROR;
368 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
369 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
370 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
371 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
373 pkgmgr_client::PkgInfoClient client(parcelable, uid,
374 pkgmgr_common::ReqType::QUERY);
375 if (!client.SendRequest()) {
377 return PMINFO_R_ERROR;
379 // TODO: deliver rawdata to reqhandler directly if server is not working
381 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
382 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
383 client.GetResultParcel()));
384 tizen_base::Parcel parcel;
385 parcel.ReadParcelable(return_parcel.get());
387 // result_list is vector of string vector
388 auto result_list = return_parcel->GetResult();
389 if (result_list.size() == 0)
390 return PMINFO_R_ENOENT;
392 for (auto result : result_list) {
393 if (result.size() != 2)
394 return PMINFO_R_ERROR;
395 if (result.front().empty() || result.front().size() == 0 ||
396 result.back().empty() || result.back().size() == 0)
397 return PMINFO_R_ERROR;
398 std::string app_control = result.front();
399 std::stringstream ss(app_control);
401 while (std::getline(ss, token, '|')) {
402 if (token.compare(std::string(operation))) {
403 char *privilege = strdup(result.back().c_str());
404 if (privilege == nullptr) {
405 LOG(ERROR) << "Out of memory";
406 return PMINFO_R_ERROR;
408 *privileges = g_list_append(*privileges, privilege);
415 extern "C" EXPORT_API int _plugininfo_get_appids(
416 const char *pkgid, const char *plugin_type,
417 const char *plugin_name, GList **list) {
418 if (!pkgid || !plugin_type || !plugin_name || !list) {
419 LOG(ERROR) << "Invalid parameter";
420 return PMINFO_R_EINVAL;
423 char *query = nullptr;
424 query = sqlite3_mprintf(
426 "package_plugin_info WHERE pkgid=%Q AND "
427 "plugin_type=%Q AND plugin_name=%Q",
428 pkgid, plugin_type, plugin_name);
429 if (query == nullptr) {
430 LOG(ERROR) << "Out of memory";
431 return PMINFO_R_ERROR;
434 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
435 new pkgmgr_common::parcel::QueryParcelable(_getuid(), std::string(query),
436 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
437 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
440 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
441 pkgmgr_common::ReqType::QUERY);
442 if (!client.SendRequest()) {
443 return PMINFO_R_ERROR;
446 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
447 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
448 client.GetResultParcel()));
449 if (return_parcel->GetCol() != 1) {
450 LOG(ERROR) << "Invalid result";
451 return PMINFO_R_ERROR;
453 // result_list is vector of string vector
454 auto& result_list = return_parcel->GetResult();
455 if (result_list.size() == 0)
456 return PMINFO_R_ENOENT;
458 for (auto result : result_list) {
459 if (result.size() != 1) {
460 LOG(ERROR) << "Invalid result";
461 g_list_free_full(*list, free);
462 return PMINFO_R_ERROR;
464 *list = g_list_append(*list, strdup(result[0].c_str()));
470 static int __convert_update_type(const char *type, pkgmgrinfo_updateinfo_update_type *convert_type)
472 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
473 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
474 *convert_type = PMINFO_UPDATEINFO_NONE;
475 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
476 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
477 *convert_type = PMINFO_UPDATEINFO_FORCE;
478 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
479 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
480 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
486 static void __free_update_info(gpointer data)
488 updateinfo_x *update_info = (updateinfo_x *)data;
489 if (update_info == nullptr)
492 if (update_info->pkgid)
493 free((void *)update_info->pkgid);
494 if (update_info->version)
495 free((void *)update_info->version);
496 free((void *)update_info);
500 extern "C" EXPORT_API int _get_pkg_updateinfo(const char *pkgid,
501 GSList **update_info_list, uid_t uid)
503 char *query = nullptr;
506 if (pkgid == nullptr)
507 query = sqlite3_mprintf(
508 "SELECT package, update_version, update_type "
509 "FROM package_update_info");
511 query = sqlite3_mprintf(
512 "SELECT package, update_version, update_type "
513 "FROM package_update_info WHERE package=%Q",
515 if (query == nullptr) {
516 LOG(ERROR) << "Out of memory";
517 return PMINFO_R_ERROR;
520 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
521 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
522 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
523 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
526 pkgmgr_client::PkgInfoClient client(parcelable, uid,
527 pkgmgr_common::ReqType::QUERY);
528 if (!client.SendRequest()) {
529 return PMINFO_R_ERROR;
532 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
533 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
534 client.GetResultParcel()));
535 if (return_parcel->GetCol() != 3) {
536 LOG(ERROR) << "Invalid result";
537 return PMINFO_R_ERROR;
540 auto result_list = return_parcel->GetResult();
541 if (result_list.size() == 0)
542 return PMINFO_R_ENOENT;
544 for (auto result : result_list) {
545 if (result.size() != 3) {
546 LOG(ERROR) << "Invalid result";
547 g_slist_free_full(*update_info_list, __free_update_info);
548 return PMINFO_R_ERROR;
550 updateinfo_x *update_info = reinterpret_cast<updateinfo_x *>(calloc(1, sizeof(updateinfo_x)));
551 if (update_info == nullptr) {
552 LOG(ERROR) << "Out of memory";
553 return PMINFO_R_ERROR;
555 update_info->pkgid = strdup(result[0].c_str());
556 update_info->version = strdup(result[1].c_str());
557 pkgmgrinfo_updateinfo_update_type convert_type;
558 ret = __convert_update_type(result[2].c_str(), &convert_type);
560 __free_update_info(update_info);
561 g_slist_free_full(*update_info_list, __free_update_info);
562 return PMINFO_R_ERROR;
564 update_info->type = static_cast<int>(convert_type);
565 *update_info_list = g_slist_prepend(*update_info_list,
572 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char *pkgid,
573 INSTALL_LOCATION location, const char *external_pkg_path,
576 char *query = nullptr;
577 const char *location_str;
578 std::vector<std::string> queries;
580 if (location == INSTALL_INTERNAL)
581 location_str = "installed_internal";
582 else if (location == INSTALL_EXTERNAL)
583 location_str = "installed_external";
585 location_str = "installed_extended";
586 /* pkgcakge_info table */
587 query = sqlite3_mprintf(
588 "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
589 location_str, external_pkg_path, pkgid);
590 queries.emplace_back(query);
593 /* package_app_info table */
594 query = sqlite3_mprintf(
595 "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
596 location_str, external_pkg_path, pkgid);
597 queries.emplace_back(query);
600 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
601 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
602 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
603 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
605 pkgmgr_client::PkgInfoClient client(parcelable, uid,
606 pkgmgr_common::ReqType::QUERY);
607 if (!client.SendRequest()) {
608 return PMINFO_R_ERROR;
611 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
612 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
613 client.GetResultParcel()));
615 auto result_list = return_parcel->GetResult();
616 if (result_list.size() != 1) {
617 LOG(ERROR) << "Invalid result";
618 return PMINFO_R_ERROR;
621 if (result_list[0].size() != 1) {
622 LOG(ERROR) << "Invalid result";
623 return PMINFO_R_ERROR;
626 LOG(ERROR) << "result : " << result_list[0][0];
627 if (result_list[0][0] != "SUCCESS")
628 return PMINFO_R_ERROR;
633 extern "C" EXPORT_API int _parser_execute_write_query(const char *query, uid_t uid)
635 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
636 new pkgmgr_common::parcel::QueryParcelable(uid, query,
637 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
638 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
640 pkgmgr_client::PkgInfoClient client(parcelable, uid,
641 pkgmgr_common::ReqType::QUERY);
642 if (!client.SendRequest()) {
646 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
647 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
648 client.GetResultParcel()));
650 auto result_list = return_parcel->GetResult();
651 if (result_list.size() != 1) {
652 LOG(ERROR) << "Invalid result";
656 if (result_list[0].size() != 1) {
657 LOG(ERROR) << "Invalid result";
661 LOG(ERROR) << "result : " << result_list[0][0];
662 if (result_list[0][0] != "SUCCESS")
668 extern "C" EXPORT_API int _parser_execute_write_queries(const char **queries, int len, uid_t uid)
670 std::vector<std::string> query_vt;
671 for (int i = 0; i < len; ++i)
672 query_vt.emplace_back(queries[i]);
674 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
675 new pkgmgr_common::parcel::QueryParcelable(uid, query_vt,
676 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
677 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
679 pkgmgr_client::PkgInfoClient client(parcelable, uid,
680 pkgmgr_common::ReqType::QUERY);
681 if (!client.SendRequest()) {
685 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
686 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
687 client.GetResultParcel()));
689 auto result_list = return_parcel->GetResult();
690 if (result_list.size() != 1) {
691 LOG(ERROR) << "Invalid result";
695 if (result_list[0].size() != 1) {
696 LOG(ERROR) << "Invalid result";
700 LOG(ERROR) << "result : " << result_list[0][0];
701 if (result_list[0][0] != "SUCCESS")
707 extern "C" EXPORT_API int _parser_insert_manifest_info(manifest_x *mfx, uid_t uid)
709 std::vector<package_x *> vt { mfx };
711 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
712 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Insert));
714 pkgmgr_client::PkgInfoClient client(parcelable, uid,
715 pkgmgr_common::ReqType::SET_PKG_INFO);
716 if (!client.SendRequest()) {
720 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
721 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
722 client.GetResultParcel()));
724 auto result_list = return_parcel->GetResult();
725 if (result_list.size() != 1) {
726 LOG(ERROR) << "Invalid result";
730 if (result_list[0].size() != 1) {
731 LOG(ERROR) << "Invalid result";
735 LOG(ERROR) << "result : " << result_list[0][0];
736 if (result_list[0][0] != "SUCCESS")
742 extern "C" EXPORT_API int _parser_update_manifest_info(manifest_x *mfx, uid_t uid)
744 std::vector<package_x *> vt { mfx };
746 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
747 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Update));
749 pkgmgr_client::PkgInfoClient client(parcelable, uid,
750 pkgmgr_common::ReqType::SET_PKG_INFO);
751 if (!client.SendRequest()) {
755 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
756 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
757 client.GetResultParcel()));
759 auto result_list = return_parcel->GetResult();
760 if (result_list.size() != 1) {
761 LOG(ERROR) << "Invalid result";
765 if (result_list[0].size() != 1) {
766 LOG(ERROR) << "Invalid result";
770 LOG(ERROR) << "result : " << result_list[0][0];
771 if (result_list[0][0] != "SUCCESS")
777 extern "C" EXPORT_API int _parser_delete_manifest_info(manifest_x *mfx, uid_t uid)
779 std::vector<package_x *> vt { mfx };
781 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
782 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Delete));
784 pkgmgr_client::PkgInfoClient client(parcelable, uid,
785 pkgmgr_common::ReqType::SET_PKG_INFO);
786 if (!client.SendRequest()) {
790 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
791 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
792 client.GetResultParcel()));
794 auto result_list = return_parcel->GetResult();
795 if (result_list.size() != 1) {
796 LOG(ERROR) << "Invalid result";
800 if (result_list[0].size() != 1) {
801 LOG(ERROR) << "Invalid result";
805 LOG(ERROR) << "result : " << result_list[0][0];
806 if (result_list[0][0] != "SUCCESS")