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& result : result_list) {
271 if (result.size() != 2 || !result.front() || !result.back() ||
272 (*result.front()).empty() || (*result.back()).empty())
273 return PMINFO_R_ERROR;
275 char* tmp_appid = strdup((*result.front()).c_str());
276 if (tmp_appid == nullptr) {
277 LOG(ERROR) << "Out of memory";
278 return PMINFO_R_ERROR;
280 char* tmp_access = strdup((*result.back()).c_str());
281 if (tmp_access == nullptr) {
282 LOG(ERROR) << "Out of memory";
284 return PMINFO_R_ERROR;
287 *access = tmp_access;
294 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
295 const char* providerid, uid_t uid, char** appid) {
296 std::shared_ptr<pcp::AbstractParcelable> parcelable(
297 new pcp::QueryParcelable(uid,
298 { QUERY_INDEX_APPINFO_GET_DATACONTROL_APPID, { providerid } },
299 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
300 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
302 pkgmgr_client::PkgInfoClient client(parcelable, uid,
303 pkgmgr_common::ReqType::QUERY);
304 if (!client.SendRequest())
305 return PMINFO_R_ERROR;
307 auto ptr = client.GetResultParcel();
308 if (ptr == nullptr) {
309 LOG(ERROR) << "Fail to get return parcelable";
310 return PMINFO_R_ERROR;
313 if (ptr->GetRequestResult() != PMINFO_R_OK) {
314 LOG(ERROR) << "Request fail";
315 return ptr->GetRequestResult();
318 if (ptr->GetType() != pcp::ParcelableType::Result) {
319 LOG(ERROR) << "Invalid parcelable type";
320 return PMINFO_R_ERROR;
323 std::shared_ptr<pcp::ResultParcelable> return_parcel(
324 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
326 // result_list is vector of string vector
327 auto& result_list = return_parcel->GetResult();
328 if (result_list.size() == 0)
329 return PMINFO_R_ENOENT;
330 for (auto& result : result_list) {
331 if (result.size() != 1 || !result.front() || (*result.front()).empty())
332 return PMINFO_R_ERROR;
333 *appid = strdup((*result.front()).c_str());
334 if (*appid == nullptr) {
335 LOG(ERROR) << "Out of memory";
336 return PMINFO_R_ERROR;
343 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
344 const char* providerid, const char* type, uid_t uid,
345 char** appid, char** trusted) {
346 std::shared_ptr<pcp::AbstractParcelable> parcelable(
347 new pcp::QueryParcelable(uid,
348 { QUERY_INDEX_APPINFO_GET_DATACONTROL_TRUSTED_INFO,
349 { providerid, type } },
350 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
351 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
353 pkgmgr_client::PkgInfoClient client(parcelable, uid,
354 pkgmgr_common::ReqType::QUERY);
355 if (!client.SendRequest())
356 return PMINFO_R_ERROR;
358 auto ptr = client.GetResultParcel();
359 if (ptr == nullptr) {
360 LOG(ERROR) << "Fail to get return parcelable";
361 return PMINFO_R_ERROR;
364 if (ptr->GetRequestResult() != PMINFO_R_OK) {
365 LOG(ERROR) << "Request fail";
366 return ptr->GetRequestResult();
369 if (ptr->GetType() != pcp::ParcelableType::Result) {
370 LOG(ERROR) << "Invalid parcelable type";
371 return PMINFO_R_ERROR;
374 std::shared_ptr<pcp::ResultParcelable> return_parcel(
375 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
377 // result_list is vector of string vector
378 auto& result_list = return_parcel->GetResult();
379 if (result_list.size() == 0)
380 return PMINFO_R_ENOENT;
381 for (auto& result : result_list) {
382 if (result.size() != 2 || !result.front() || !result.back() ||
383 (*result.front()).empty() || (*result.back()).empty())
384 return PMINFO_R_ERROR;
386 char* tmp_appid = strdup((*result.front()).c_str());
387 if (tmp_appid == nullptr) {
388 LOG(ERROR) << "Out of memory";
389 return PMINFO_R_ERROR;
391 char* tmp_trusted = strdup((*result.back()).c_str());
392 if (tmp_trusted == nullptr) {
393 LOG(ERROR) << "Out of memory";
395 return PMINFO_R_ERROR;
398 *trusted = tmp_trusted;
405 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
406 const char* providerid, const char* type, uid_t uid, GList** privileges) {
407 std::shared_ptr<pcp::AbstractParcelable> parcelable(
408 new pcp::QueryParcelable(uid,
409 { QUERY_INDEX_APPINFO_GET_DATACONTROL_PRIVILEGES,
410 { providerid, type } },
411 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
412 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
414 pkgmgr_client::PkgInfoClient client(parcelable, uid,
415 pkgmgr_common::ReqType::QUERY);
416 if (!client.SendRequest())
417 return PMINFO_R_ERROR;
419 auto ptr = client.GetResultParcel();
420 if (ptr == nullptr) {
421 LOG(ERROR) << "Fail to get return parcelable";
422 return PMINFO_R_ERROR;
425 if (ptr->GetRequestResult() != PMINFO_R_OK) {
426 LOG(ERROR) << "Request fail";
427 return ptr->GetRequestResult();
430 if (ptr->GetType() != pcp::ParcelableType::Result) {
431 LOG(ERROR) << "Invalid parcelable type";
432 return PMINFO_R_ERROR;
435 std::shared_ptr<pcp::ResultParcelable> return_parcel(
436 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
438 // result_list is vector of string vector
439 auto& result_list = return_parcel->GetResult();
440 if (result_list.size() == 0)
441 return PMINFO_R_ENOENT;
443 for (auto& result : result_list) {
444 if (result.size() != 1 || !result.front() || (*result.front()).empty())
445 return PMINFO_R_ERROR;
446 char* privilege = strdup((*result.front()).c_str());
447 if (privilege == nullptr) {
448 LOG(ERROR) << "Out of memory";
449 return PMINFO_R_ERROR;
451 *privileges = g_list_append(*privileges, privilege);
457 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
458 const char* appid, const char* operation, uid_t uid, GList** privileges) {
459 std::shared_ptr<pcp::AbstractParcelable> parcelable(
460 new pcp::QueryParcelable(uid,
461 { QUERY_INDEX_APPINFO_GET_APPCONTROL_PRIVILEGES, { appid } },
462 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
463 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
465 pkgmgr_client::PkgInfoClient client(parcelable, uid,
466 pkgmgr_common::ReqType::QUERY);
467 if (!client.SendRequest())
468 return PMINFO_R_ERROR;
470 auto ptr = client.GetResultParcel();
471 if (ptr == nullptr) {
472 LOG(ERROR) << "Fail to get return parcelable";
473 return PMINFO_R_ERROR;
476 if (ptr->GetRequestResult() != PMINFO_R_OK) {
477 LOG(ERROR) << "Request fail";
478 return ptr->GetRequestResult();
481 if (ptr->GetType() != pcp::ParcelableType::Result) {
482 LOG(ERROR) << "Invalid parcelable type";
483 return PMINFO_R_ERROR;
486 std::shared_ptr<pcp::ResultParcelable> return_parcel(
487 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
489 // result_list is vector of string vector
490 auto& result_list = return_parcel->GetResult();
491 if (result_list.size() == 0)
492 return PMINFO_R_ENOENT;
494 for (auto& result : result_list) {
495 if (result.size() != 2 || !result.front() || !result.back() ||
496 (*result.front()).empty() || (*result.back()).empty())
497 return PMINFO_R_ERROR;
498 std::stringstream ss((*result.front()));
500 while (std::getline(ss, token, '|')) {
501 if (token.compare(std::string(operation))) {
502 char* privilege = strdup((*result.back()).c_str());
503 if (privilege == nullptr) {
504 LOG(ERROR) << "Out of memory";
505 return PMINFO_R_ERROR;
507 *privileges = g_list_append(*privileges, privilege);
514 extern "C" EXPORT_API int _plugininfo_get_appids(
515 const char* pkgid, const char* plugin_type,
516 const char* plugin_name, GList** list) {
517 if (!pkgid || !plugin_type || !plugin_name || !list) {
518 LOG(ERROR) << "Invalid parameter";
519 return PMINFO_R_EINVAL;
522 std::shared_ptr<pcp::AbstractParcelable> parcelable(
523 new pcp::QueryParcelable(_getuid(),
524 { QUERY_INDEX_PLUGININFO_GET_APPIDS,
525 { pkgid, plugin_type, plugin_name } },
526 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
527 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
529 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
530 pkgmgr_common::ReqType::QUERY);
531 if (!client.SendRequest())
532 return PMINFO_R_ERROR;
534 auto ptr = client.GetResultParcel();
535 if (ptr == nullptr) {
536 LOG(ERROR) << "Fail to get return parcelable";
537 return PMINFO_R_ERROR;
540 if (ptr->GetRequestResult() != PMINFO_R_OK) {
541 LOG(ERROR) << "Request fail";
542 return ptr->GetRequestResult();
545 if (ptr->GetType() != pcp::ParcelableType::Result) {
546 LOG(ERROR) << "Invalid parcelable type";
547 return PMINFO_R_ERROR;
550 std::shared_ptr<pcp::ResultParcelable> return_parcel(
551 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
553 if (return_parcel->GetCol() != 1) {
554 LOG(ERROR) << "Invalid result";
555 return PMINFO_R_ERROR;
557 // result_list is vector of string vector
558 auto& result_list = return_parcel->GetResult();
559 if (result_list.size() == 0)
560 return PMINFO_R_ENOENT;
562 for (auto& result : result_list) {
563 if (result.size() != 1) {
564 LOG(ERROR) << "Invalid result";
565 g_list_free_full(*list, free);
566 return PMINFO_R_ERROR;
568 *list = g_list_append(*list, strdup((*result[0]).c_str()));
574 static int __convert_update_type(const char* type,
575 pkgmgrinfo_updateinfo_update_type* convert_type) {
576 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
577 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
578 *convert_type = PMINFO_UPDATEINFO_NONE;
579 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
580 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
581 *convert_type = PMINFO_UPDATEINFO_FORCE;
582 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
583 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
584 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
590 static void __free_update_info(gpointer data) {
591 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(data);
592 if (update_info == nullptr)
595 if (update_info->pkgid)
596 free(reinterpret_cast<void*>(update_info->pkgid));
597 if (update_info->version)
598 free(reinterpret_cast<void*>(update_info->version));
599 free(reinterpret_cast<void*>(update_info));
602 extern "C" EXPORT_API int _get_pkg_updateinfo(const char* pkgid,
603 GSList** update_info_list, uid_t uid) {
606 std::pair<int, std::vector<const char*>> info;
608 if (pkgid == nullptr) {
609 info = std::pair<int, std::vector<const char*>>(
610 QUERY_INDEX_GET_PKG_UPDATEINFO_1, {});
612 info = std::pair<int, std::vector<const char*>>(
613 QUERY_INDEX_GET_PKG_UPDATEINFO_2, { pkgid });
616 std::shared_ptr<pcp::AbstractParcelable> parcelable(
617 new pcp::QueryParcelable(uid, std::move(info),
618 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
619 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
621 pkgmgr_client::PkgInfoClient client(parcelable, uid,
622 pkgmgr_common::ReqType::QUERY);
623 if (!client.SendRequest())
624 return PMINFO_R_ERROR;
626 auto ptr = client.GetResultParcel();
627 if (ptr == nullptr) {
628 LOG(ERROR) << "Fail to get return parcelable";
629 return PMINFO_R_ERROR;
632 if (ptr->GetRequestResult() != PMINFO_R_OK) {
633 LOG(ERROR) << "Request fail";
634 return ptr->GetRequestResult();
637 if (ptr->GetType() != pcp::ParcelableType::Result) {
638 LOG(ERROR) << "Invalid parcelable type";
639 return PMINFO_R_ERROR;
642 std::shared_ptr<pcp::ResultParcelable> return_parcel(
643 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
645 if (return_parcel->GetCol() != 3) {
646 LOG(ERROR) << "Invalid result";
647 return PMINFO_R_ERROR;
650 auto& result_list = return_parcel->GetResult();
651 if (result_list.size() == 0)
652 return PMINFO_R_ENOENT;
654 GSList* tmp_list = nullptr;
655 for (auto& result : result_list) {
656 if (result.size() != 3) {
657 LOG(ERROR) << "Invalid result";
658 g_slist_free_full(tmp_list, __free_update_info);
659 return PMINFO_R_ERROR;
661 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(
662 calloc(1, sizeof(updateinfo_x)));
663 if (update_info == nullptr) {
664 LOG(ERROR) << "Out of memory";
665 g_slist_free_full(tmp_list, __free_update_info);
666 return PMINFO_R_ERROR;
668 update_info->pkgid = strdup((*result[0]).c_str());
669 update_info->version = strdup((*result[1]).c_str());
670 pkgmgrinfo_updateinfo_update_type convert_type;
671 ret = __convert_update_type((*result[2]).c_str(), &convert_type);
673 __free_update_info(update_info);
674 g_slist_free_full(tmp_list, __free_update_info);
675 return PMINFO_R_ERROR;
677 update_info->type = static_cast<int>(convert_type);
678 tmp_list = g_slist_prepend(tmp_list, update_info);
681 *update_info_list = tmp_list;
685 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char* pkgid,
686 INSTALL_LOCATION location, const char* external_pkg_path, uid_t uid) {
687 const char* location_str;
689 if (location == INSTALL_INTERNAL)
690 location_str = "installed_internal";
691 else if (location == INSTALL_EXTERNAL)
692 location_str = "installed_external";
694 location_str = "installed_extended";
696 std::shared_ptr<pcp::AbstractParcelable> parcelable(
697 new pcp::QueryParcelable(uid, { {
698 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_1, {
704 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_2, {
711 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
712 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
714 pkgmgr_client::PkgInfoClient client(parcelable, uid,
715 pkgmgr_common::ReqType::QUERY);
716 if (!client.SendRequest())
717 return PMINFO_R_ERROR;
719 auto ptr = client.GetResultParcel();
720 if (ptr == nullptr) {
721 LOG(ERROR) << "Fail to get return parcelable";
722 return PMINFO_R_ERROR;
725 if (ptr->GetRequestResult() != PMINFO_R_OK) {
726 LOG(ERROR) << "Request fail";
727 return ptr->GetRequestResult();
730 if (ptr->GetType() != pcp::ParcelableType::Result) {
731 LOG(ERROR) << "Invalid parcelable type";
732 return PMINFO_R_ERROR;
738 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char* l_pkgid,
739 const char* r_pkgid, pkgmgrinfo_cert_compare_result_type_e* result) {
740 std::shared_ptr<pcp::AbstractParcelable> parcelable(
741 new pcp::QueryParcelable(0,
742 { QUERY_INDEX_CERTINFO_COMPARE_PKG_CERTINFO, { l_pkgid, r_pkgid } },
743 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
744 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
745 pkgmgr_client::PkgInfoClient client(parcelable, 0,
746 pkgmgr_common::ReqType::QUERY);
747 if (!client.SendRequest())
748 return PMINFO_R_ERROR;
750 auto ptr = client.GetResultParcel();
751 if (ptr == nullptr) {
752 LOG(ERROR) << "Fail to get return parcelable";
753 return PMINFO_R_ERROR;
756 if (ptr->GetRequestResult() != PMINFO_R_OK) {
757 LOG(ERROR) << "Request fail";
758 return ptr->GetRequestResult();
761 if (ptr->GetType() != pcp::ParcelableType::Result) {
762 LOG(ERROR) << "Invalid parcelable type";
763 return PMINFO_R_ERROR;
766 std::shared_ptr<pcp::ResultParcelable> return_parcel(
767 std::static_pointer_cast<pcp::ResultParcelable>(
770 auto& certinfo_list = return_parcel->GetResult();
772 std::map<std::string, std::string> result_map;
773 result_map.insert(make_pair(std::string(l_pkgid), "-1"));
774 result_map.insert(make_pair(std::string(r_pkgid), "-1"));
776 for (auto& certinfo : certinfo_list)
777 result_map[*certinfo.front()] = *certinfo.back();
779 auto l_iter = result_map.find(l_pkgid);
780 auto r_iter = result_map.find(r_pkgid);
781 if (l_iter->second == "-1" && r_iter->second == "-1")
782 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
783 else if (l_iter->second == "-1")
784 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
785 else if (r_iter->second == "-1")
786 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
787 else if (l_iter->second == r_iter->second)
788 *result = PMINFO_CERT_COMPARE_MATCH;
790 *result = PMINFO_CERT_COMPARE_MISMATCH;
795 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
796 const char* l_appid, const char* r_appid,
797 pkgmgrinfo_cert_compare_result_type_e* result) {
798 std::shared_ptr<pcp::AbstractParcelable> parcelable(
799 new pcp::QueryParcelable(uid,
800 { QUERY_INDEX_CERTINFO_COMPARE_APP_CERTINFO, { l_appid, r_appid } },
801 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
802 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
803 pkgmgr_client::PkgInfoClient client(parcelable, uid,
804 pkgmgr_common::ReqType::QUERY);
805 if (!client.SendRequest())
806 return PMINFO_R_ERROR;
808 auto ptr = client.GetResultParcel();
809 if (ptr == nullptr) {
810 LOG(ERROR) << "Fail to get return parcelable";
811 return PMINFO_R_ERROR;
814 if (ptr->GetRequestResult() != PMINFO_R_OK) {
815 LOG(ERROR) << "Request fail";
816 return ptr->GetRequestResult();
819 if (ptr->GetType() != pcp::ParcelableType::Result) {
820 LOG(ERROR) << "Invalid parcelable type";
821 return PMINFO_R_ERROR;
824 std::shared_ptr<pcp::ResultParcelable> return_parcel(
825 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
827 auto& pkgid_list = return_parcel->GetResult();
828 std::map<std::string, std::string> result_map;
829 for (auto& pkgid : pkgid_list)
830 result_map.insert(make_pair(*pkgid.front(), *pkgid.back()));
832 auto l_iter = result_map.find(l_appid);
833 if (l_iter == result_map.end()) {
834 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
835 << " for uid " << uid;
836 return PMINFO_R_ENOENT;
838 auto r_iter = result_map.find(r_appid);
839 if (r_iter == result_map.end()) {
840 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
841 << " for uid " << uid;
842 return PMINFO_R_ENOENT;
845 const char* l_pkgid = l_iter->second.c_str();
846 const char* r_pkgid = r_iter->second.c_str();
848 return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
851 extern "C" EXPORT_API int _parser_execute_write_query(
852 int query_index, const char** query_args, unsigned int arg_cnt, uid_t uid) {
853 std::vector<const char*> args;
855 for (unsigned int i = 0; i < arg_cnt; i++)
856 args.push_back(query_args[i]);
858 std::shared_ptr<pcp::AbstractParcelable> parcelable(
859 new pcp::QueryParcelable(uid, { query_index, std::move(args) },
860 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
861 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
863 pkgmgr_client::PkgInfoClient client(parcelable, uid,
864 pkgmgr_common::ReqType::QUERY);
865 if (!client.SendRequest())
868 auto ptr = client.GetResultParcel();
869 if (ptr == nullptr) {
870 LOG(ERROR) << "Fail to get return parcelable";
874 if (ptr->GetRequestResult() != PMINFO_R_OK) {
875 LOG(ERROR) << "Request fail";
879 if (ptr->GetType() != pcp::ParcelableType::Result) {
880 LOG(ERROR) << "Invalid parcelable type";
886 extern "C" EXPORT_API int _parser_execute_write_queries(
887 int query_index, const char*** query_args, unsigned int arg_cnt,
888 unsigned int query_cnt, uid_t uid) {
889 std::vector<std::pair<int, std::vector<const char*>>> queries;
891 for (unsigned int i = 0; i < query_cnt; i++) {
892 std::vector<const char*> args;
893 for (unsigned int j = 0; j < arg_cnt; j++)
894 args.push_back(query_args[i][j]);
895 queries.push_back({ query_index, std::move(args) });
898 std::shared_ptr<pcp::AbstractParcelable> parcelable(
899 new pcp::QueryParcelable(uid, std::move(queries),
900 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
901 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
903 pkgmgr_client::PkgInfoClient client(parcelable, uid,
904 pkgmgr_common::ReqType::QUERY);
905 if (!client.SendRequest())
908 auto ptr = client.GetResultParcel();
909 if (ptr == nullptr) {
910 LOG(ERROR) << "Fail to get return parcelable";
914 if (ptr->GetRequestResult() != PMINFO_R_OK) {
915 LOG(ERROR) << "Request fail";
919 if (ptr->GetType() != pcp::ParcelableType::Result) {
920 LOG(ERROR) << "Invalid parcelable type";
927 extern "C" EXPORT_API int _parser_insert_manifest_info(
928 manifest_x* mfx, uid_t uid) {
930 std::make_shared<pcp::PkgInfoParcelable>(uid,
931 std::vector<package_x*>{mfx}, WriteType::Insert, false);
933 pkgmgr_client::PkgInfoClient client(parcelable, uid,
934 pkgmgr_common::ReqType::SET_PKG_INFO);
935 if (!client.SendRequest())
938 auto ptr = client.GetResultParcel();
939 if (ptr == nullptr) {
940 LOG(ERROR) << "Fail to get return parcelable";
944 if (ptr->GetRequestResult() != PMINFO_R_OK) {
945 LOG(ERROR) << "Request fail";
949 if (ptr->GetType() != pcp::ParcelableType::Result) {
950 LOG(ERROR) << "Invalid parcelable type";
957 extern "C" EXPORT_API int _parser_update_manifest_info(
958 manifest_x* mfx, uid_t uid) {
960 std::make_shared<pcp::PkgInfoParcelable>(uid,
961 std::vector<package_x*>{mfx}, WriteType::Update, false);
963 pkgmgr_client::PkgInfoClient client(parcelable, uid,
964 pkgmgr_common::ReqType::SET_PKG_INFO);
965 if (!client.SendRequest())
968 auto ptr = client.GetResultParcel();
969 if (ptr == nullptr) {
970 LOG(ERROR) << "Fail to get return parcelable";
974 if (ptr->GetRequestResult() != PMINFO_R_OK) {
975 LOG(ERROR) << "Request fail";
979 if (ptr->GetType() != pcp::ParcelableType::Result) {
980 LOG(ERROR) << "Invalid parcelable type";
987 extern "C" EXPORT_API int _parser_delete_manifest_info(
988 manifest_x* mfx, uid_t uid) {
990 std::make_shared<pcp::PkgInfoParcelable>(uid,
991 std::vector<package_x*>{mfx}, WriteType::Delete, false);
993 pkgmgr_client::PkgInfoClient client(parcelable, uid,
994 pkgmgr_common::ReqType::SET_PKG_INFO);
995 if (!client.SendRequest())
998 auto ptr = client.GetResultParcel();
999 if (ptr == nullptr) {
1000 LOG(ERROR) << "Fail to get return parcelable";
1004 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1005 LOG(ERROR) << "Request fail";
1009 if (ptr->GetType() != pcp::ParcelableType::Result) {
1010 LOG(ERROR) << "Invalid parcelable type";
1017 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1018 pkgmgr_certinfo_x* cert, uid_t uid) {
1019 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1020 new pcp::CertInfoParcelable(uid, cert, false));
1021 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1022 pkgmgr_common::ReqType::SET_CERT_INFO);
1024 if (!client.SendRequest())
1025 return PMINFO_R_ERROR;
1027 auto ptr = client.GetResultParcel();
1028 if (ptr == nullptr) {
1029 LOG(ERROR) << "Fail to get return parcelable";
1030 return PMINFO_R_ERROR;
1033 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1034 LOG(ERROR) << "Request fail";
1035 return ptr->GetRequestResult();
1038 if (ptr->GetType() != pcp::ParcelableType::Result) {
1039 LOG(ERROR) << "Invalid parcelable type";
1040 return PMINFO_R_ERROR;
1046 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char* pkgid,
1047 pkgmgr_certinfo_x* cert, uid_t uid) {
1048 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1049 new pcp::CertInfoParcelable(uid,
1050 std::string(pkgid)));
1052 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1053 pkgmgr_common::ReqType::GET_CERT_INFO);
1054 if (!client.SendRequest())
1055 return PMINFO_R_ERROR;
1057 auto ptr = client.GetResultParcel();
1058 if (ptr == nullptr) {
1059 LOG(ERROR) << "Fail to get return parcelable";
1060 return PMINFO_R_ERROR;
1063 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1064 LOG(ERROR) << "Request fail";
1065 return ptr->GetRequestResult();
1068 if (ptr->GetType() != pcp::ParcelableType::CertInfo) {
1069 LOG(ERROR) << "Invalid parcelable type";
1070 return PMINFO_R_ERROR;
1073 std::shared_ptr<pcp::CertInfoParcelable> return_parcel(
1074 std::static_pointer_cast<pcp::CertInfoParcelable>(ptr));
1076 pkgmgr_certinfo_x* certinfo = return_parcel->ExtractCertInfo();
1077 if (certinfo == nullptr)
1078 return PMINFO_R_ERROR;
1080 cert->for_all_users = certinfo->for_all_users;
1081 cert->pkgid = certinfo->pkgid;
1082 certinfo->pkgid = nullptr;
1083 cert->cert_value = certinfo->cert_value;
1084 certinfo->cert_value = nullptr;
1085 for (int i = 0; i < MAX_CERT_TYPE; i++) {
1086 cert->cert_info[i] = certinfo->cert_info[i];
1087 certinfo->cert_info[i] = nullptr;
1089 for (int i = 0; i < MAX_CERT_TYPE; i++)
1090 cert->cert_id[i] = certinfo->cert_id[i];
1097 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char* pkgid) {
1098 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1099 new pcp::QueryParcelable(0,
1100 { QUERY_INDEX_PKGINFO_DELETE_CERTINFO, { pkgid } },
1101 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1102 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1104 pkgmgr_client::PkgInfoClient client(parcelable, 0,
1105 pkgmgr_common::ReqType::QUERY);
1106 if (!client.SendRequest())
1107 return PMINFO_R_ERROR;
1109 auto ptr = client.GetResultParcel();
1110 if (ptr == nullptr) {
1111 LOG(ERROR) << "Fail to get return parcelable";
1112 return PMINFO_R_ERROR;
1115 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1116 LOG(ERROR) << "Request fail";
1117 return PMINFO_R_ERROR;
1120 if (ptr->GetType() != pcp::ParcelableType::Result) {
1121 LOG(ERROR) << "Invalid parcelable type";
1122 return PMINFO_R_ERROR;
1128 extern "C" EXPORT_API int _parser_clear_cache_memory_db(uid_t uid) {
1129 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1130 new pcp::CommandParcelable(uid, CommandType::RemoveCache));
1132 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1133 pkgmgr_common::ReqType::COMMAND);
1135 if (!client.SendRequest())
1136 return PMINFO_R_ERROR;
1138 auto ptr = client.GetResultParcel();
1139 if (ptr == nullptr) {
1140 LOG(ERROR) << "Fail to get return parcelable";
1141 return PMINFO_R_ERROR;
1144 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1145 LOG(ERROR) << "Request fail";
1146 return PMINFO_R_ERROR;
1149 if (ptr->GetType() != pcp::ParcelableType::Result) {
1150 LOG(ERROR) << "Invalid parcelable type";
1151 return PMINFO_R_ERROR;