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>
32 #include "pkgmgr_parser.h"
33 #include "pkgmgrinfo_private.h"
34 #include "pkgmgr_query_index.h"
36 #include "client/pkginfo_client.hh"
37 #include "common/database/abstract_db_handler.hh"
38 #include "common/database/pkg_set_db_handler.hh"
39 #include "common/parcel/appinfo_parcelable.hh"
40 #include "common/parcel/certinfo_parcelable.hh"
41 #include "common/parcel/command_parcelable.hh"
42 #include "common/parcel/depinfo_parcelable.hh"
43 #include "common/parcel/filter_parcelable.hh"
44 #include "common/parcel/pkginfo_parcelable.hh"
45 #include "common/parcel/query_parcelable.hh"
46 #include "common/parcel/result_parcelable.hh"
53 #define LOG_TAG "PKGMGR_INFO"
58 #define EXPORT_API __attribute__((visibility("default")))
60 namespace pcp = pkgmgr_common::parcel;
61 namespace pcd = pkgmgr_common::database;
63 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
64 pkgmgrinfo_filter_x* filter, int flag, GHashTable* packages) {
65 std::shared_ptr<pcp::AbstractParcelable> parcelable(
66 new pcp::FilterParcelable(uid,
67 static_cast<pkgmgrinfo_filter_x*>(filter), flag, false));
69 pkgmgr_client::PkgInfoClient client(parcelable, uid,
70 pkgmgr_common::ReqType::GET_PKG_INFO);
71 if (!client.SendRequest())
72 return PMINFO_R_ERROR;
74 auto ptr = client.GetResultParcel();
76 LOG(ERROR) << "Fail to get return parcelable";
77 return PMINFO_R_ERROR;
80 if (ptr->GetRequestResult() != PMINFO_R_OK) {
81 if (ptr->GetRequestResult() == PMINFO_R_ERROR)
82 LOG(ERROR) << "Request fail";
83 return ptr->GetRequestResult();
86 if (ptr->GetType() != pcp::ParcelableType::PkgInfo) {
87 LOG(ERROR) << "Invalid parcelable type";
88 return PMINFO_R_ERROR;
91 std::shared_ptr<pcp::PkgInfoParcelable> return_parcel(
92 std::static_pointer_cast<pcp::PkgInfoParcelable>(
95 auto result_list = return_parcel->ExtractPkgInfo();
96 if (result_list.size() == 0) {
97 LOG(DEBUG) << "No packages meets given condition for user " << uid;
98 return PMINFO_R_ENOENT;
100 for (auto pkginfo : result_list)
101 g_hash_table_insert(packages, (gpointer)pkginfo->package,
107 extern "C" EXPORT_API int _pkginfo_get_depends_on(uid_t uid,
108 const char* pkgid, GList** dependencies) {
109 std::shared_ptr<pcp::AbstractParcelable> parcelable(
110 new pcp::DepInfoParcelable(std::string(pkgid)));
112 pkgmgr_client::PkgInfoClient client(parcelable, uid,
113 pkgmgr_common::ReqType::GET_PKG_DEP_INFO);
114 if (!client.SendRequest())
115 return PMINFO_R_ERROR;
117 auto ptr = client.GetResultParcel();
118 if (ptr == nullptr) {
119 LOG(ERROR) << "Fail to get return parcelable";
120 return PMINFO_R_ERROR;
123 if (ptr->GetRequestResult() != PMINFO_R_OK) {
124 LOG(ERROR) << "Request fail";
125 return ptr->GetRequestResult();
128 if (ptr->GetType() != pcp::ParcelableType::DepInfo) {
129 LOG(ERROR) << "Invalid parcelable type";
130 return PMINFO_R_ERROR;
133 std::shared_ptr<pcp::DepInfoParcelable> return_parcel(
134 std::static_pointer_cast<pcp::DepInfoParcelable>(ptr));
136 auto dependency_list = return_parcel->ExtractDependencyInfo();
137 for (auto dependency : dependency_list)
138 *dependencies = g_list_prepend(*dependencies, dependency);
142 extern "C" EXPORT_API int _appinfo_get_applications(uid_t uid,
143 pkgmgrinfo_filter_x* filter, int flag, GHashTable* packages) {
144 std::shared_ptr<pcp::AbstractParcelable> parcelable(
145 new pcp::FilterParcelable(uid,
146 static_cast<pkgmgrinfo_filter_x*>(filter), flag, false));
148 pkgmgr_client::PkgInfoClient client(
149 parcelable, uid, pkgmgr_common::ReqType::GET_APP_INFO);
150 if (!client.SendRequest())
151 return PMINFO_R_ERROR;
153 auto ptr = client.GetResultParcel();
154 if (ptr == nullptr) {
155 LOG(ERROR) << "Fail to get return parcelable";
156 return PMINFO_R_ERROR;
159 int ret = ptr->GetRequestResult();
160 if (ret != PMINFO_R_OK) {
161 if (ret == PMINFO_R_ENOENT)
162 LOG(DEBUG) << "No such application";
164 LOG(ERROR) << "Request fail";
168 if (ptr->GetType() != pcp::ParcelableType::AppInfo) {
169 LOG(ERROR) << "Invalid parcelable type";
170 return PMINFO_R_ERROR;
173 std::shared_ptr<pcp::AppInfoParcelable> return_parcel(
174 std::static_pointer_cast<pcp::AppInfoParcelable>(ptr));
176 std::vector<application_x*> result_list = return_parcel->ExtractAppInfo();
177 for (application_x* app : result_list)
178 g_hash_table_insert(packages, (gpointer)app->appid,
184 extern "C" EXPORT_API char* _appinfo_get_localed_label(
185 const char* appid, const char* locale, uid_t uid) {
186 std::shared_ptr<pcp::AbstractParcelable> parcelable(
187 new pcp::QueryParcelable(uid,
188 { QUERY_INDEX_APPINFO_GET_LOCALED_LABEL, { appid, locale, appid } },
189 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
190 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
192 pkgmgr_client::PkgInfoClient client(parcelable, uid,
193 pkgmgr_common::ReqType::QUERY);
194 if (!client.SendRequest())
196 auto ptr = client.GetResultParcel();
197 if (ptr == nullptr) {
198 LOG(ERROR) << "Fail to get return parcelable";
202 if (ptr->GetRequestResult() != PMINFO_R_OK) {
203 LOG(ERROR) << "Request fail";
207 if (ptr->GetType() != pcp::ParcelableType::Result) {
208 LOG(ERROR) << "Invalid parcelable type";
212 std::shared_ptr<pcp::ResultParcelable> return_parcel(
213 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
215 // result_list is vector of string vector
216 char* label = nullptr;
217 auto& result_list = return_parcel->GetResult();
218 for (auto& result : result_list) {
219 // result is string vector
220 // it only has one string or not.
221 if (!result.front() || (*result.front()).empty())
223 label = strdup((*result.front()).c_str());
224 if (label == nullptr) {
225 LOG(ERROR) << "Out of memory";
234 extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
235 const char* providerid, const char* type, uid_t uid,
236 char** appid, char** access) {
237 std::shared_ptr<pcp::AbstractParcelable> parcelable(
238 new pcp::QueryParcelable(uid,
239 { QUERY_INDEX_APPINFO_GET_DATACONTROL_INFO, { providerid, type } },
240 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
241 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
243 pkgmgr_client::PkgInfoClient client(parcelable, uid,
244 pkgmgr_common::ReqType::QUERY);
245 if (!client.SendRequest())
246 return PMINFO_R_ERROR;
248 auto ptr = client.GetResultParcel();
249 if (ptr == nullptr) {
250 LOG(ERROR) << "Fail to get return parcelable";
251 return PMINFO_R_ERROR;
254 if (ptr->GetRequestResult() != PMINFO_R_OK) {
255 LOG(ERROR) << "Request fail";
256 return ptr->GetRequestResult();
259 if (ptr->GetType() != pcp::ParcelableType::Result) {
260 LOG(ERROR) << "Invalid parcelable type";
261 return PMINFO_R_ERROR;
264 std::shared_ptr<pcp::ResultParcelable> return_parcel(
265 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
267 auto& result_list = return_parcel->GetResult();
268 if (result_list.size() == 0)
269 return PMINFO_R_ENOENT;
270 for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
271 const auto& result = *it;
272 if (result.size() != 2 || !result.front() || !result.back() ||
273 (*result.front()).empty() || (*result.back()).empty())
276 char* tmp_appid = strdup((*result.front()).c_str());
277 if (tmp_appid == nullptr) {
278 LOG(ERROR) << "Out of memory";
279 return PMINFO_R_ERROR;
281 char* tmp_access = strdup((*result.back()).c_str());
282 if (tmp_access == nullptr) {
283 LOG(ERROR) << "Out of memory";
285 return PMINFO_R_ERROR;
288 *access = tmp_access;
293 return PMINFO_R_ENOENT;
296 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
297 const char* providerid, uid_t uid, char** appid) {
298 std::shared_ptr<pcp::AbstractParcelable> parcelable(
299 new pcp::QueryParcelable(uid,
300 { QUERY_INDEX_APPINFO_GET_DATACONTROL_APPID, { providerid } },
301 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
302 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
304 pkgmgr_client::PkgInfoClient client(parcelable, uid,
305 pkgmgr_common::ReqType::QUERY);
306 if (!client.SendRequest())
307 return PMINFO_R_ERROR;
309 auto ptr = client.GetResultParcel();
310 if (ptr == nullptr) {
311 LOG(ERROR) << "Fail to get return parcelable";
312 return PMINFO_R_ERROR;
315 if (ptr->GetRequestResult() != PMINFO_R_OK) {
316 LOG(ERROR) << "Request fail";
317 return ptr->GetRequestResult();
320 if (ptr->GetType() != pcp::ParcelableType::Result) {
321 LOG(ERROR) << "Invalid parcelable type";
322 return PMINFO_R_ERROR;
325 std::shared_ptr<pcp::ResultParcelable> return_parcel(
326 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
328 // result_list is vector of string vector
329 auto& result_list = return_parcel->GetResult();
330 if (result_list.size() == 0)
331 return PMINFO_R_ENOENT;
332 for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
333 const auto& result = *it;
334 if (result.size() != 1 || !result.front() || (*result.front()).empty())
336 *appid = strdup((*result.front()).c_str());
337 if (*appid == nullptr) {
338 LOG(ERROR) << "Out of memory";
339 return PMINFO_R_ERROR;
344 return PMINFO_R_ENOENT;
347 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
348 const char* providerid, const char* type, uid_t uid,
349 char** appid, char** trusted) {
350 std::shared_ptr<pcp::AbstractParcelable> parcelable(
351 new pcp::QueryParcelable(uid,
352 { QUERY_INDEX_APPINFO_GET_DATACONTROL_TRUSTED_INFO,
353 { providerid, type } },
354 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
355 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
357 pkgmgr_client::PkgInfoClient client(parcelable, uid,
358 pkgmgr_common::ReqType::QUERY);
359 if (!client.SendRequest())
360 return PMINFO_R_ERROR;
362 auto ptr = client.GetResultParcel();
363 if (ptr == nullptr) {
364 LOG(ERROR) << "Fail to get return parcelable";
365 return PMINFO_R_ERROR;
368 if (ptr->GetRequestResult() != PMINFO_R_OK) {
369 LOG(ERROR) << "Request fail";
370 return ptr->GetRequestResult();
373 if (ptr->GetType() != pcp::ParcelableType::Result) {
374 LOG(ERROR) << "Invalid parcelable type";
375 return PMINFO_R_ERROR;
378 std::shared_ptr<pcp::ResultParcelable> return_parcel(
379 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
381 // result_list is vector of string vector
382 auto& result_list = return_parcel->GetResult();
383 if (result_list.size() == 0)
384 return PMINFO_R_ENOENT;
385 for (auto it = result_list.rbegin(); it != result_list.rend(); it++) {
386 const auto& result = *it;
387 if (result.size() != 2 || !result.front() || !result.back() ||
388 (*result.front()).empty() || (*result.back()).empty())
391 char* tmp_appid = strdup((*result.front()).c_str());
392 if (tmp_appid == nullptr) {
393 LOG(ERROR) << "Out of memory";
394 return PMINFO_R_ERROR;
396 char* tmp_trusted = strdup((*result.back()).c_str());
397 if (tmp_trusted == nullptr) {
398 LOG(ERROR) << "Out of memory";
400 return PMINFO_R_ERROR;
403 *trusted = tmp_trusted;
407 return PMINFO_R_ENOENT;
410 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
411 const char* providerid, const char* type, uid_t uid, GList** privileges) {
412 std::shared_ptr<pcp::AbstractParcelable> parcelable(
413 new pcp::QueryParcelable(uid,
414 { QUERY_INDEX_APPINFO_GET_DATACONTROL_PRIVILEGES,
415 { providerid, type } },
416 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
417 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
419 pkgmgr_client::PkgInfoClient client(parcelable, uid,
420 pkgmgr_common::ReqType::QUERY);
421 if (!client.SendRequest())
422 return PMINFO_R_ERROR;
424 auto ptr = client.GetResultParcel();
425 if (ptr == nullptr) {
426 LOG(ERROR) << "Fail to get return parcelable";
427 return PMINFO_R_ERROR;
430 if (ptr->GetRequestResult() != PMINFO_R_OK) {
431 LOG(ERROR) << "Request fail";
432 return ptr->GetRequestResult();
435 if (ptr->GetType() != pcp::ParcelableType::Result) {
436 LOG(ERROR) << "Invalid parcelable type";
437 return PMINFO_R_ERROR;
440 std::shared_ptr<pcp::ResultParcelable> return_parcel(
441 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
443 // result_list is vector of string vector
444 auto& result_list = return_parcel->GetResult();
445 if (result_list.size() == 0)
446 return PMINFO_R_ENOENT;
448 for (auto& result : result_list) {
449 if (result.size() != 1 || !result.front() || (*result.front()).empty())
450 return PMINFO_R_ERROR;
451 char* privilege = strdup((*result.front()).c_str());
452 if (privilege == nullptr) {
453 LOG(ERROR) << "Out of memory";
454 return PMINFO_R_ERROR;
456 *privileges = g_list_append(*privileges, privilege);
462 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
463 const char* appid, const char* operation, uid_t uid, GList** privileges) {
464 std::shared_ptr<pcp::AbstractParcelable> parcelable(
465 new pcp::QueryParcelable(uid,
466 { QUERY_INDEX_APPINFO_GET_APPCONTROL_PRIVILEGES, { appid } },
467 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
468 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
470 pkgmgr_client::PkgInfoClient client(parcelable, uid,
471 pkgmgr_common::ReqType::QUERY);
472 if (!client.SendRequest())
473 return PMINFO_R_ERROR;
475 auto ptr = client.GetResultParcel();
476 if (ptr == nullptr) {
477 LOG(ERROR) << "Fail to get return parcelable";
478 return PMINFO_R_ERROR;
481 if (ptr->GetRequestResult() != PMINFO_R_OK) {
482 LOG(ERROR) << "Request fail";
483 return ptr->GetRequestResult();
486 if (ptr->GetType() != pcp::ParcelableType::Result) {
487 LOG(ERROR) << "Invalid parcelable type";
488 return PMINFO_R_ERROR;
491 std::shared_ptr<pcp::ResultParcelable> return_parcel(
492 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
494 // result_list is vector of string vector
495 auto& result_list = return_parcel->GetResult();
496 if (result_list.size() == 0)
497 return PMINFO_R_ENOENT;
499 for (auto& result : result_list) {
500 if (result.size() != 2 || !result.front() || !result.back() ||
501 (*result.front()).empty() || (*result.back()).empty())
502 return PMINFO_R_ERROR;
503 std::stringstream ss((*result.front()));
505 while (std::getline(ss, token, '|')) {
506 if (token.compare(std::string(operation))) {
507 char* privilege = strdup((*result.back()).c_str());
508 if (privilege == nullptr) {
509 LOG(ERROR) << "Out of memory";
510 return PMINFO_R_ERROR;
512 *privileges = g_list_append(*privileges, privilege);
519 extern "C" EXPORT_API int _plugininfo_get_appids(
520 const char* pkgid, const char* plugin_type,
521 const char* plugin_name, GList** list) {
522 if (!pkgid || !plugin_type || !plugin_name || !list) {
523 LOG(ERROR) << "Invalid parameter";
524 return PMINFO_R_EINVAL;
527 std::shared_ptr<pcp::AbstractParcelable> parcelable(
528 new pcp::QueryParcelable(_getuid(),
529 { QUERY_INDEX_PLUGININFO_GET_APPIDS,
530 { pkgid, plugin_type, plugin_name } },
531 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
532 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
534 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
535 pkgmgr_common::ReqType::QUERY);
536 if (!client.SendRequest())
537 return PMINFO_R_ERROR;
539 auto ptr = client.GetResultParcel();
540 if (ptr == nullptr) {
541 LOG(ERROR) << "Fail to get return parcelable";
542 return PMINFO_R_ERROR;
545 if (ptr->GetRequestResult() != PMINFO_R_OK) {
546 LOG(ERROR) << "Request fail";
547 return ptr->GetRequestResult();
550 if (ptr->GetType() != pcp::ParcelableType::Result) {
551 LOG(ERROR) << "Invalid parcelable type";
552 return PMINFO_R_ERROR;
555 std::shared_ptr<pcp::ResultParcelable> return_parcel(
556 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
558 if (return_parcel->GetCol() != 1) {
559 LOG(ERROR) << "Invalid result";
560 return PMINFO_R_ERROR;
562 // result_list is vector of string vector
563 auto& result_list = return_parcel->GetResult();
564 if (result_list.size() == 0)
565 return PMINFO_R_ENOENT;
567 for (auto& result : result_list) {
568 if (result.size() != 1) {
569 LOG(ERROR) << "Invalid result";
570 g_list_free_full(*list, free);
571 return PMINFO_R_ERROR;
573 *list = g_list_append(*list, strdup((*result[0]).c_str()));
579 static int __convert_update_type(const char* type,
580 pkgmgrinfo_updateinfo_update_type* convert_type) {
581 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
582 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
583 *convert_type = PMINFO_UPDATEINFO_NONE;
584 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
585 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
586 *convert_type = PMINFO_UPDATEINFO_FORCE;
587 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
588 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
589 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
595 static void __free_update_info(gpointer data) {
596 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(data);
597 if (update_info == nullptr)
600 if (update_info->pkgid)
601 free(reinterpret_cast<void*>(update_info->pkgid));
602 if (update_info->version)
603 free(reinterpret_cast<void*>(update_info->version));
604 free(reinterpret_cast<void*>(update_info));
607 extern "C" EXPORT_API int _get_pkg_updateinfo(const char* pkgid,
608 GSList** update_info_list, uid_t uid) {
611 std::pair<int, std::vector<const char*>> info;
613 if (pkgid == nullptr) {
614 info = std::pair<int, std::vector<const char*>>(
615 QUERY_INDEX_GET_PKG_UPDATEINFO_1, {});
617 info = std::pair<int, std::vector<const char*>>(
618 QUERY_INDEX_GET_PKG_UPDATEINFO_2, { pkgid });
621 std::shared_ptr<pcp::AbstractParcelable> parcelable(
622 new pcp::QueryParcelable(uid, std::move(info),
623 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
624 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
626 pkgmgr_client::PkgInfoClient client(parcelable, uid,
627 pkgmgr_common::ReqType::QUERY);
628 if (!client.SendRequest())
629 return PMINFO_R_ERROR;
631 auto ptr = client.GetResultParcel();
632 if (ptr == nullptr) {
633 LOG(ERROR) << "Fail to get return parcelable";
634 return PMINFO_R_ERROR;
637 if (ptr->GetRequestResult() != PMINFO_R_OK) {
638 LOG(ERROR) << "Request fail";
639 return ptr->GetRequestResult();
642 if (ptr->GetType() != pcp::ParcelableType::Result) {
643 LOG(ERROR) << "Invalid parcelable type";
644 return PMINFO_R_ERROR;
647 std::shared_ptr<pcp::ResultParcelable> return_parcel(
648 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
650 if (return_parcel->GetCol() != 3) {
651 LOG(ERROR) << "Invalid result";
652 return PMINFO_R_ERROR;
655 auto& result_list = return_parcel->GetResult();
656 if (result_list.size() == 0)
657 return PMINFO_R_ENOENT;
659 GSList* tmp_list = nullptr;
660 for (auto& result : result_list) {
661 if (result.size() != 3) {
662 LOG(ERROR) << "Invalid result";
663 g_slist_free_full(tmp_list, __free_update_info);
664 return PMINFO_R_ERROR;
666 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(
667 calloc(1, sizeof(updateinfo_x)));
668 if (update_info == nullptr) {
669 LOG(ERROR) << "Out of memory";
670 g_slist_free_full(tmp_list, __free_update_info);
671 return PMINFO_R_ERROR;
673 update_info->pkgid = strdup((*result[0]).c_str());
674 update_info->version = strdup((*result[1]).c_str());
675 pkgmgrinfo_updateinfo_update_type convert_type;
676 ret = __convert_update_type((*result[2]).c_str(), &convert_type);
678 __free_update_info(update_info);
679 g_slist_free_full(tmp_list, __free_update_info);
680 return PMINFO_R_ERROR;
682 update_info->type = static_cast<int>(convert_type);
683 tmp_list = g_slist_append(tmp_list, update_info);
686 *update_info_list = tmp_list;
690 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char* pkgid,
691 INSTALL_LOCATION location, const char* external_pkg_path, uid_t uid) {
692 const char* location_str;
694 if (location == INSTALL_INTERNAL)
695 location_str = "installed_internal";
696 else if (location == INSTALL_EXTERNAL)
697 location_str = "installed_external";
699 location_str = "installed_extended";
701 std::shared_ptr<pcp::AbstractParcelable> parcelable(
702 new pcp::QueryParcelable(uid, { {
703 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_1, {
709 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_2, {
716 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
717 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
719 pkgmgr_client::PkgInfoClient client(parcelable, uid,
720 pkgmgr_common::ReqType::QUERY);
721 if (!client.SendRequest())
722 return PMINFO_R_ERROR;
724 auto ptr = client.GetResultParcel();
725 if (ptr == nullptr) {
726 LOG(ERROR) << "Fail to get return parcelable";
727 return PMINFO_R_ERROR;
730 if (ptr->GetRequestResult() != PMINFO_R_OK) {
731 LOG(ERROR) << "Request fail";
732 return ptr->GetRequestResult();
735 if (ptr->GetType() != pcp::ParcelableType::Result) {
736 LOG(ERROR) << "Invalid parcelable type";
737 return PMINFO_R_ERROR;
743 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char* l_pkgid,
744 const char* r_pkgid, pkgmgrinfo_cert_compare_result_type_e* result) {
745 std::shared_ptr<pcp::AbstractParcelable> parcelable(
746 new pcp::QueryParcelable(0,
747 { QUERY_INDEX_CERTINFO_COMPARE_PKG_CERTINFO, { l_pkgid, r_pkgid } },
748 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
749 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
750 pkgmgr_client::PkgInfoClient client(parcelable, 0,
751 pkgmgr_common::ReqType::QUERY);
752 if (!client.SendRequest())
753 return PMINFO_R_ERROR;
755 auto ptr = client.GetResultParcel();
756 if (ptr == nullptr) {
757 LOG(ERROR) << "Fail to get return parcelable";
758 return PMINFO_R_ERROR;
761 if (ptr->GetRequestResult() != PMINFO_R_OK) {
762 LOG(ERROR) << "Request fail";
763 return ptr->GetRequestResult();
766 if (ptr->GetType() != pcp::ParcelableType::Result) {
767 LOG(ERROR) << "Invalid parcelable type";
768 return PMINFO_R_ERROR;
771 std::shared_ptr<pcp::ResultParcelable> return_parcel(
772 std::static_pointer_cast<pcp::ResultParcelable>(
775 auto& certinfo_list = return_parcel->GetResult();
777 std::map<std::string, std::string> result_map;
778 result_map.insert(make_pair(std::string(l_pkgid), "-1"));
779 result_map.insert(make_pair(std::string(r_pkgid), "-1"));
781 for (auto& certinfo : certinfo_list)
782 result_map[*certinfo.front()] = *certinfo.back();
784 auto l_iter = result_map.find(l_pkgid);
785 auto r_iter = result_map.find(r_pkgid);
786 if (l_iter->second == "-1" && r_iter->second == "-1")
787 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
788 else if (l_iter->second == "-1")
789 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
790 else if (r_iter->second == "-1")
791 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
792 else if (l_iter->second == r_iter->second)
793 *result = PMINFO_CERT_COMPARE_MATCH;
795 *result = PMINFO_CERT_COMPARE_MISMATCH;
800 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
801 const char* l_appid, const char* r_appid,
802 pkgmgrinfo_cert_compare_result_type_e* result) {
803 std::shared_ptr<pcp::AbstractParcelable> parcelable(
804 new pcp::QueryParcelable(uid,
805 { QUERY_INDEX_CERTINFO_COMPARE_APP_CERTINFO, { l_appid, r_appid } },
806 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
807 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
808 pkgmgr_client::PkgInfoClient client(parcelable, uid,
809 pkgmgr_common::ReqType::QUERY);
810 if (!client.SendRequest())
811 return PMINFO_R_ERROR;
813 auto ptr = client.GetResultParcel();
814 if (ptr == nullptr) {
815 LOG(ERROR) << "Fail to get return parcelable";
816 return PMINFO_R_ERROR;
819 if (ptr->GetRequestResult() != PMINFO_R_OK) {
820 LOG(ERROR) << "Request fail";
821 return ptr->GetRequestResult();
824 if (ptr->GetType() != pcp::ParcelableType::Result) {
825 LOG(ERROR) << "Invalid parcelable type";
826 return PMINFO_R_ERROR;
829 std::shared_ptr<pcp::ResultParcelable> return_parcel(
830 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
832 auto& pkgid_list = return_parcel->GetResult();
833 std::map<std::string, std::string> result_map;
834 for (auto& pkgid : pkgid_list)
835 result_map.insert(make_pair(*pkgid.front(), *pkgid.back()));
837 auto l_iter = result_map.find(l_appid);
838 if (l_iter == result_map.end()) {
839 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
840 << " for uid " << uid;
841 return PMINFO_R_ENOENT;
843 auto r_iter = result_map.find(r_appid);
844 if (r_iter == result_map.end()) {
845 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
846 << " for uid " << uid;
847 return PMINFO_R_ENOENT;
850 const char* l_pkgid = l_iter->second.c_str();
851 const char* r_pkgid = r_iter->second.c_str();
853 return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
856 extern "C" EXPORT_API int _parser_execute_write_query(
857 int query_index, const char** query_args, unsigned int arg_cnt, uid_t uid) {
858 std::vector<const char*> args;
860 for (unsigned int i = 0; i < arg_cnt; i++)
861 args.push_back(query_args[i]);
863 std::shared_ptr<pcp::AbstractParcelable> parcelable(
864 new pcp::QueryParcelable(uid, { query_index, std::move(args) },
865 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
866 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
868 pkgmgr_client::PkgInfoClient client(parcelable, uid,
869 pkgmgr_common::ReqType::QUERY);
870 if (!client.SendRequest())
873 auto ptr = client.GetResultParcel();
874 if (ptr == nullptr) {
875 LOG(ERROR) << "Fail to get return parcelable";
879 if (ptr->GetRequestResult() != PMINFO_R_OK) {
880 LOG(ERROR) << "Request fail";
884 if (ptr->GetType() != pcp::ParcelableType::Result) {
885 LOG(ERROR) << "Invalid parcelable type";
891 extern "C" EXPORT_API int _parser_execute_write_queries(
892 int query_index, const char*** query_args, unsigned int arg_cnt,
893 unsigned int query_cnt, uid_t uid) {
894 std::vector<std::pair<int, std::vector<const char*>>> queries;
896 for (unsigned int i = 0; i < query_cnt; i++) {
897 std::vector<const char*> args;
898 for (unsigned int j = 0; j < arg_cnt; j++)
899 args.push_back(query_args[i][j]);
900 queries.push_back({ query_index, std::move(args) });
903 std::shared_ptr<pcp::AbstractParcelable> parcelable(
904 new pcp::QueryParcelable(uid, std::move(queries),
905 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
906 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
908 pkgmgr_client::PkgInfoClient client(parcelable, uid,
909 pkgmgr_common::ReqType::QUERY);
910 if (!client.SendRequest())
913 auto ptr = client.GetResultParcel();
914 if (ptr == nullptr) {
915 LOG(ERROR) << "Fail to get return parcelable";
919 if (ptr->GetRequestResult() != PMINFO_R_OK) {
920 LOG(ERROR) << "Request fail";
924 if (ptr->GetType() != pcp::ParcelableType::Result) {
925 LOG(ERROR) << "Invalid parcelable type";
932 extern "C" EXPORT_API int _parser_insert_manifest_info(
933 manifest_x* mfx, uid_t uid) {
935 std::make_shared<pcp::PkgInfoParcelable>(uid,
936 std::vector<package_x*>{mfx}, WriteType::Insert, false);
938 pkgmgr_client::PkgInfoClient client(parcelable, uid,
939 pkgmgr_common::ReqType::SET_PKG_INFO);
940 if (!client.SendRequest())
943 auto ptr = client.GetResultParcel();
944 if (ptr == nullptr) {
945 LOG(ERROR) << "Fail to get return parcelable";
949 if (ptr->GetRequestResult() != PMINFO_R_OK) {
950 LOG(ERROR) << "Request fail";
954 if (ptr->GetType() != pcp::ParcelableType::Result) {
955 LOG(ERROR) << "Invalid parcelable type";
962 extern "C" EXPORT_API int _parser_update_manifest_info(
963 manifest_x* mfx, uid_t uid) {
965 std::make_shared<pcp::PkgInfoParcelable>(uid,
966 std::vector<package_x*>{mfx}, WriteType::Update, false);
968 pkgmgr_client::PkgInfoClient client(parcelable, uid,
969 pkgmgr_common::ReqType::SET_PKG_INFO);
970 if (!client.SendRequest())
973 auto ptr = client.GetResultParcel();
974 if (ptr == nullptr) {
975 LOG(ERROR) << "Fail to get return parcelable";
979 if (ptr->GetRequestResult() != PMINFO_R_OK) {
980 LOG(ERROR) << "Request fail";
984 if (ptr->GetType() != pcp::ParcelableType::Result) {
985 LOG(ERROR) << "Invalid parcelable type";
992 extern "C" EXPORT_API int _parser_delete_manifest_info(
993 manifest_x* mfx, uid_t uid) {
995 std::make_shared<pcp::PkgInfoParcelable>(uid,
996 std::vector<package_x*>{mfx}, WriteType::Delete, false);
998 pkgmgr_client::PkgInfoClient client(parcelable, uid,
999 pkgmgr_common::ReqType::SET_PKG_INFO);
1000 if (!client.SendRequest())
1003 auto ptr = client.GetResultParcel();
1004 if (ptr == nullptr) {
1005 LOG(ERROR) << "Fail to get return parcelable";
1009 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1010 LOG(ERROR) << "Request fail";
1014 if (ptr->GetType() != pcp::ParcelableType::Result) {
1015 LOG(ERROR) << "Invalid parcelable type";
1022 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1023 pkgmgr_certinfo_x* cert, uid_t uid) {
1024 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1025 new pcp::CertInfoParcelable(uid, cert, false));
1026 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1027 pkgmgr_common::ReqType::SET_CERT_INFO);
1029 if (!client.SendRequest())
1030 return PMINFO_R_ERROR;
1032 auto ptr = client.GetResultParcel();
1033 if (ptr == nullptr) {
1034 LOG(ERROR) << "Fail to get return parcelable";
1035 return PMINFO_R_ERROR;
1038 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1039 LOG(ERROR) << "Request fail";
1040 return ptr->GetRequestResult();
1043 if (ptr->GetType() != pcp::ParcelableType::Result) {
1044 LOG(ERROR) << "Invalid parcelable type";
1045 return PMINFO_R_ERROR;
1051 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char* pkgid,
1052 pkgmgr_certinfo_x* cert, uid_t uid) {
1053 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1054 new pcp::CertInfoParcelable(uid,
1055 std::string(pkgid)));
1057 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1058 pkgmgr_common::ReqType::GET_CERT_INFO);
1059 if (!client.SendRequest())
1060 return PMINFO_R_ERROR;
1062 auto ptr = client.GetResultParcel();
1063 if (ptr == nullptr) {
1064 LOG(ERROR) << "Fail to get return parcelable";
1065 return PMINFO_R_ERROR;
1068 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1069 LOG(ERROR) << "Request fail";
1070 return ptr->GetRequestResult();
1073 if (ptr->GetType() != pcp::ParcelableType::CertInfo) {
1074 LOG(ERROR) << "Invalid parcelable type";
1075 return PMINFO_R_ERROR;
1078 std::shared_ptr<pcp::CertInfoParcelable> return_parcel(
1079 std::static_pointer_cast<pcp::CertInfoParcelable>(ptr));
1081 pkgmgr_certinfo_x* certinfo = return_parcel->ExtractCertInfo();
1082 if (certinfo == nullptr)
1083 return PMINFO_R_ERROR;
1085 cert->for_all_users = certinfo->for_all_users;
1086 cert->pkgid = certinfo->pkgid;
1087 certinfo->pkgid = nullptr;
1088 cert->cert_value = certinfo->cert_value;
1089 certinfo->cert_value = nullptr;
1090 for (int i = 0; i < MAX_CERT_TYPE; i++) {
1091 cert->cert_info[i] = certinfo->cert_info[i];
1092 certinfo->cert_info[i] = nullptr;
1094 for (int i = 0; i < MAX_CERT_TYPE; i++)
1095 cert->cert_id[i] = certinfo->cert_id[i];
1102 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char* pkgid) {
1103 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1104 new pcp::QueryParcelable(0,
1105 { QUERY_INDEX_PKGINFO_DELETE_CERTINFO, { pkgid } },
1106 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1107 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1109 pkgmgr_client::PkgInfoClient client(parcelable, 0,
1110 pkgmgr_common::ReqType::QUERY);
1111 if (!client.SendRequest())
1112 return PMINFO_R_ERROR;
1114 auto ptr = client.GetResultParcel();
1115 if (ptr == nullptr) {
1116 LOG(ERROR) << "Fail to get return parcelable";
1117 return PMINFO_R_ERROR;
1120 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1121 LOG(ERROR) << "Request fail";
1122 return PMINFO_R_ERROR;
1125 if (ptr->GetType() != pcp::ParcelableType::Result) {
1126 LOG(ERROR) << "Invalid parcelable type";
1127 return PMINFO_R_ERROR;
1133 extern "C" EXPORT_API int _parser_clear_cache_memory_db(uid_t uid) {
1134 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1135 new pcp::CommandParcelable(uid, CommandType::RemoveCache));
1137 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1138 pkgmgr_common::ReqType::COMMAND);
1140 if (!client.SendRequest())
1141 return PMINFO_R_ERROR;
1143 auto ptr = client.GetResultParcel();
1144 if (ptr == nullptr) {
1145 LOG(ERROR) << "Fail to get return parcelable";
1146 return PMINFO_R_ERROR;
1149 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1150 LOG(ERROR) << "Request fail";
1151 return PMINFO_R_ERROR;
1154 if (ptr->GetType() != pcp::ParcelableType::Result) {
1155 LOG(ERROR) << "Invalid parcelable type";
1156 return PMINFO_R_ERROR;