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().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().empty() || result.back().empty())
272 return PMINFO_R_ERROR;
273 *appid = strdup(result.front().c_str());
274 *access = strdup(result.back().c_str());
275 if (*appid == nullptr || *access == nullptr) {
276 LOG(ERROR) << "Out of memory";
277 return PMINFO_R_ERROR;
284 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
285 const char* providerid, uid_t uid, char** appid) {
286 std::shared_ptr<pcp::AbstractParcelable> parcelable(
287 new pcp::QueryParcelable(uid,
288 { QUERY_INDEX_APPINFO_GET_DATACONTROL_APPID, { providerid } },
289 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
290 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
292 pkgmgr_client::PkgInfoClient client(parcelable, uid,
293 pkgmgr_common::ReqType::QUERY);
294 if (!client.SendRequest())
295 return PMINFO_R_ERROR;
297 auto ptr = client.GetResultParcel();
298 if (ptr == nullptr) {
299 LOG(ERROR) << "Fail to get return parcelable";
300 return PMINFO_R_ERROR;
303 if (ptr->GetRequestResult() != PMINFO_R_OK) {
304 LOG(ERROR) << "Request fail";
305 return ptr->GetRequestResult();
308 if (ptr->GetType() != pcp::ParcelableType::Result) {
309 LOG(ERROR) << "Invalid parcelable type";
310 return PMINFO_R_ERROR;
313 std::shared_ptr<pcp::ResultParcelable> return_parcel(
314 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
316 // result_list is vector of string vector
317 auto result_list = return_parcel->GetResult();
318 if (result_list.size() == 0)
319 return PMINFO_R_ENOENT;
320 for (auto& result : result_list) {
321 if (result.size() != 1 || result.front().empty())
322 return PMINFO_R_ERROR;
323 *appid = strdup(result.front().c_str());
324 if (*appid == nullptr) {
325 LOG(ERROR) << "Out of memory";
326 return PMINFO_R_ERROR;
333 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
334 const char* providerid, const char* type, uid_t uid,
335 char** appid, char** trusted) {
336 std::shared_ptr<pcp::AbstractParcelable> parcelable(
337 new pcp::QueryParcelable(uid,
338 { QUERY_INDEX_APPINFO_GET_DATACONTROL_TRUSTED_INFO,
339 { providerid, type } },
340 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
341 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
343 pkgmgr_client::PkgInfoClient client(parcelable, uid,
344 pkgmgr_common::ReqType::QUERY);
345 if (!client.SendRequest())
346 return PMINFO_R_ERROR;
348 auto ptr = client.GetResultParcel();
349 if (ptr == nullptr) {
350 LOG(ERROR) << "Fail to get return parcelable";
351 return PMINFO_R_ERROR;
354 if (ptr->GetRequestResult() != PMINFO_R_OK) {
355 LOG(ERROR) << "Request fail";
356 return ptr->GetRequestResult();
359 if (ptr->GetType() != pcp::ParcelableType::Result) {
360 LOG(ERROR) << "Invalid parcelable type";
361 return PMINFO_R_ERROR;
364 std::shared_ptr<pcp::ResultParcelable> return_parcel(
365 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
367 // result_list is vector of string vector
368 auto result_list = return_parcel->GetResult();
369 if (result_list.size() == 0)
370 return PMINFO_R_ENOENT;
371 for (auto& result : result_list) {
372 if (result.size() != 2 || result.front().empty() || result.back().empty())
373 return PMINFO_R_ERROR;
374 *appid = strdup(result.front().c_str());
375 *trusted = strdup(result.back().c_str());
376 if (*appid == nullptr || *trusted == nullptr) {
377 LOG(ERROR) << "Out of memory";
378 return PMINFO_R_ERROR;
385 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
386 const char* providerid, const char* type, uid_t uid, GList** privileges) {
387 std::shared_ptr<pcp::AbstractParcelable> parcelable(
388 new pcp::QueryParcelable(uid,
389 { QUERY_INDEX_APPINFO_GET_DATACONTROL_PRIVILEGES,
390 { providerid, type } },
391 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
392 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
394 pkgmgr_client::PkgInfoClient client(parcelable, uid,
395 pkgmgr_common::ReqType::QUERY);
396 if (!client.SendRequest())
397 return PMINFO_R_ERROR;
399 auto ptr = client.GetResultParcel();
400 if (ptr == nullptr) {
401 LOG(ERROR) << "Fail to get return parcelable";
402 return PMINFO_R_ERROR;
405 if (ptr->GetRequestResult() != PMINFO_R_OK) {
406 LOG(ERROR) << "Request fail";
407 return ptr->GetRequestResult();
410 if (ptr->GetType() != pcp::ParcelableType::Result) {
411 LOG(ERROR) << "Invalid parcelable type";
412 return PMINFO_R_ERROR;
415 std::shared_ptr<pcp::ResultParcelable> return_parcel(
416 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
418 // result_list is vector of string vector
419 auto result_list = return_parcel->GetResult();
420 if (result_list.size() == 0)
421 return PMINFO_R_ENOENT;
423 for (auto& result : result_list) {
424 if (result.size() != 1 || result.front().empty())
425 return PMINFO_R_ERROR;
426 char* privilege = strdup(result.front().c_str());
427 if (privilege == nullptr) {
428 LOG(ERROR) << "Out of memory";
429 return PMINFO_R_ERROR;
431 *privileges = g_list_append(*privileges, privilege);
437 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
438 const char* appid, const char* operation, uid_t uid, GList** privileges) {
439 std::shared_ptr<pcp::AbstractParcelable> parcelable(
440 new pcp::QueryParcelable(uid,
441 { QUERY_INDEX_APPINFO_GET_APPCONTROL_PRIVILEGES, { appid } },
442 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
443 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
445 pkgmgr_client::PkgInfoClient client(parcelable, uid,
446 pkgmgr_common::ReqType::QUERY);
447 if (!client.SendRequest())
448 return PMINFO_R_ERROR;
450 auto ptr = client.GetResultParcel();
451 if (ptr == nullptr) {
452 LOG(ERROR) << "Fail to get return parcelable";
453 return PMINFO_R_ERROR;
456 if (ptr->GetRequestResult() != PMINFO_R_OK) {
457 LOG(ERROR) << "Request fail";
458 return ptr->GetRequestResult();
461 if (ptr->GetType() != pcp::ParcelableType::Result) {
462 LOG(ERROR) << "Invalid parcelable type";
463 return PMINFO_R_ERROR;
466 std::shared_ptr<pcp::ResultParcelable> return_parcel(
467 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
469 // result_list is vector of string vector
470 auto result_list = return_parcel->GetResult();
471 if (result_list.size() == 0)
472 return PMINFO_R_ENOENT;
474 for (auto& result : result_list) {
475 if (result.size() != 2 || result.front().empty() || result.back().empty())
476 return PMINFO_R_ERROR;
477 std::stringstream ss(result.front());
479 while (std::getline(ss, token, '|')) {
480 if (token.compare(std::string(operation))) {
481 char* privilege = strdup(result.back().c_str());
482 if (privilege == nullptr) {
483 LOG(ERROR) << "Out of memory";
484 return PMINFO_R_ERROR;
486 *privileges = g_list_append(*privileges, privilege);
493 extern "C" EXPORT_API int _plugininfo_get_appids(
494 const char* pkgid, const char* plugin_type,
495 const char* plugin_name, GList** list) {
496 if (!pkgid || !plugin_type || !plugin_name || !list) {
497 LOG(ERROR) << "Invalid parameter";
498 return PMINFO_R_EINVAL;
501 std::shared_ptr<pcp::AbstractParcelable> parcelable(
502 new pcp::QueryParcelable(_getuid(),
503 { QUERY_INDEX_PLUGININFO_GET_APPIDS,
504 { pkgid, plugin_type, plugin_name } },
505 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
506 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
508 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
509 pkgmgr_common::ReqType::QUERY);
510 if (!client.SendRequest())
511 return PMINFO_R_ERROR;
513 auto ptr = client.GetResultParcel();
514 if (ptr == nullptr) {
515 LOG(ERROR) << "Fail to get return parcelable";
516 return PMINFO_R_ERROR;
519 if (ptr->GetRequestResult() != PMINFO_R_OK) {
520 LOG(ERROR) << "Request fail";
521 return ptr->GetRequestResult();
524 if (ptr->GetType() != pcp::ParcelableType::Result) {
525 LOG(ERROR) << "Invalid parcelable type";
526 return PMINFO_R_ERROR;
529 std::shared_ptr<pcp::ResultParcelable> return_parcel(
530 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
532 if (return_parcel->GetCol() != 1) {
533 LOG(ERROR) << "Invalid result";
534 return PMINFO_R_ERROR;
536 // result_list is vector of string vector
537 auto &result_list = return_parcel->GetResult();
538 if (result_list.size() == 0)
539 return PMINFO_R_ENOENT;
541 for (auto& result : result_list) {
542 if (result.size() != 1) {
543 LOG(ERROR) << "Invalid result";
544 g_list_free_full(*list, free);
545 return PMINFO_R_ERROR;
547 *list = g_list_append(*list, strdup(result[0].c_str()));
553 static int __convert_update_type(const char* type,
554 pkgmgrinfo_updateinfo_update_type* convert_type) {
555 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
556 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
557 *convert_type = PMINFO_UPDATEINFO_NONE;
558 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
559 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
560 *convert_type = PMINFO_UPDATEINFO_FORCE;
561 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
562 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
563 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
569 static void __free_update_info(gpointer data) {
570 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(data);
571 if (update_info == nullptr)
574 if (update_info->pkgid)
575 free(reinterpret_cast<void*>(update_info->pkgid));
576 if (update_info->version)
577 free(reinterpret_cast<void*>(update_info->version));
578 free(reinterpret_cast<void*>(update_info));
581 extern "C" EXPORT_API int _get_pkg_updateinfo(const char* pkgid,
582 GSList** update_info_list, uid_t uid) {
585 std::pair<int, std::vector<std::string>> info;
587 if (pkgid == nullptr) {
588 info = std::pair<int, std::vector<std::string>>(
589 QUERY_INDEX_GET_PKG_UPDATEINFO_1, {});
591 info = std::pair<int, std::vector<std::string>>(
592 QUERY_INDEX_GET_PKG_UPDATEINFO_2, { pkgid });
595 std::shared_ptr<pcp::AbstractParcelable> parcelable(
596 new pcp::QueryParcelable(uid, std::move(info),
597 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
598 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
600 pkgmgr_client::PkgInfoClient client(parcelable, uid,
601 pkgmgr_common::ReqType::QUERY);
602 if (!client.SendRequest())
603 return PMINFO_R_ERROR;
605 auto ptr = client.GetResultParcel();
606 if (ptr == nullptr) {
607 LOG(ERROR) << "Fail to get return parcelable";
608 return PMINFO_R_ERROR;
611 if (ptr->GetRequestResult() != PMINFO_R_OK) {
612 LOG(ERROR) << "Request fail";
613 return ptr->GetRequestResult();
616 if (ptr->GetType() != pcp::ParcelableType::Result) {
617 LOG(ERROR) << "Invalid parcelable type";
618 return PMINFO_R_ERROR;
621 std::shared_ptr<pcp::ResultParcelable> return_parcel(
622 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
624 if (return_parcel->GetCol() != 3) {
625 LOG(ERROR) << "Invalid result";
626 return PMINFO_R_ERROR;
629 auto result_list = return_parcel->GetResult();
630 if (result_list.size() == 0)
631 return PMINFO_R_ENOENT;
633 for (auto& result : result_list) {
634 if (result.size() != 3) {
635 LOG(ERROR) << "Invalid result";
636 g_slist_free_full(*update_info_list, __free_update_info);
637 return PMINFO_R_ERROR;
639 updateinfo_x* update_info = reinterpret_cast<updateinfo_x*>(
640 calloc(1, sizeof(updateinfo_x)));
641 if (update_info == nullptr) {
642 LOG(ERROR) << "Out of memory";
643 return PMINFO_R_ERROR;
645 update_info->pkgid = strdup(result[0].c_str());
646 update_info->version = strdup(result[1].c_str());
647 pkgmgrinfo_updateinfo_update_type convert_type;
648 ret = __convert_update_type(result[2].c_str(), &convert_type);
650 __free_update_info(update_info);
651 g_slist_free_full(*update_info_list, __free_update_info);
652 return PMINFO_R_ERROR;
654 update_info->type = static_cast<int>(convert_type);
655 *update_info_list = g_slist_prepend(*update_info_list,
662 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char* pkgid,
663 INSTALL_LOCATION location, const char* external_pkg_path, uid_t uid) {
664 const char* location_str;
666 if (location == INSTALL_INTERNAL)
667 location_str = "installed_internal";
668 else if (location == INSTALL_EXTERNAL)
669 location_str = "installed_external";
671 location_str = "installed_extended";
673 std::shared_ptr<pcp::AbstractParcelable> parcelable(
674 new pcp::QueryParcelable(uid, { {
675 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_1, {
681 QUERY_INDEX_PKGINFO_SET_USR_INSTALLED_STORAGE_2, {
688 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
689 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
691 pkgmgr_client::PkgInfoClient client(parcelable, uid,
692 pkgmgr_common::ReqType::QUERY);
693 if (!client.SendRequest())
694 return PMINFO_R_ERROR;
696 auto ptr = client.GetResultParcel();
697 if (ptr == nullptr) {
698 LOG(ERROR) << "Fail to get return parcelable";
699 return PMINFO_R_ERROR;
702 if (ptr->GetRequestResult() != PMINFO_R_OK) {
703 LOG(ERROR) << "Request fail";
704 return ptr->GetRequestResult();
707 if (ptr->GetType() != pcp::ParcelableType::Result) {
708 LOG(ERROR) << "Invalid parcelable type";
709 return PMINFO_R_ERROR;
715 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char* l_pkgid,
716 const char* r_pkgid, pkgmgrinfo_cert_compare_result_type_e* result) {
717 std::shared_ptr<pcp::AbstractParcelable> parcelable(
718 new pcp::QueryParcelable(0,
719 { QUERY_INDEX_CERTINFO_COMPARE_PKG_CERTINFO, { l_pkgid, r_pkgid } },
720 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
721 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
722 pkgmgr_client::PkgInfoClient client(parcelable, 0,
723 pkgmgr_common::ReqType::QUERY);
724 if (!client.SendRequest())
725 return PMINFO_R_ERROR;
727 auto ptr = client.GetResultParcel();
728 if (ptr == nullptr) {
729 LOG(ERROR) << "Fail to get return parcelable";
730 return PMINFO_R_ERROR;
733 if (ptr->GetRequestResult() != PMINFO_R_OK) {
734 LOG(ERROR) << "Request fail";
735 return ptr->GetRequestResult();
738 if (ptr->GetType() != pcp::ParcelableType::Result) {
739 LOG(ERROR) << "Invalid parcelable type";
740 return PMINFO_R_ERROR;
743 std::shared_ptr<pcp::ResultParcelable> return_parcel(
744 std::static_pointer_cast<pcp::ResultParcelable>(
747 auto certinfo_list = return_parcel->GetResult();
749 std::map<std::string, std::string> result_map;
750 result_map.insert(make_pair(std::string(l_pkgid), "-1"));
751 result_map.insert(make_pair(std::string(r_pkgid), "-1"));
753 for (auto& certinfo : certinfo_list)
754 result_map[certinfo.front()] = certinfo.back();
756 auto l_iter = result_map.find(l_pkgid);
757 auto r_iter = result_map.find(r_pkgid);
758 if (l_iter->second == "-1" && r_iter->second == "-1")
759 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
760 else if (l_iter->second == "-1")
761 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
762 else if (r_iter->second == "-1")
763 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
764 else if (l_iter->second == r_iter->second)
765 *result = PMINFO_CERT_COMPARE_MATCH;
767 *result = PMINFO_CERT_COMPARE_MISMATCH;
772 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
773 const char* l_appid, const char* r_appid,
774 pkgmgrinfo_cert_compare_result_type_e* result) {
775 std::shared_ptr<pcp::AbstractParcelable> parcelable(
776 new pcp::QueryParcelable(uid,
777 { QUERY_INDEX_CERTINFO_COMPARE_APP_CERTINFO, { l_appid, r_appid } },
778 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
779 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
780 pkgmgr_client::PkgInfoClient client(parcelable, uid,
781 pkgmgr_common::ReqType::QUERY);
782 if (!client.SendRequest())
783 return PMINFO_R_ERROR;
785 auto ptr = client.GetResultParcel();
786 if (ptr == nullptr) {
787 LOG(ERROR) << "Fail to get return parcelable";
788 return PMINFO_R_ERROR;
791 if (ptr->GetRequestResult() != PMINFO_R_OK) {
792 LOG(ERROR) << "Request fail";
793 return ptr->GetRequestResult();
796 if (ptr->GetType() != pcp::ParcelableType::Result) {
797 LOG(ERROR) << "Invalid parcelable type";
798 return PMINFO_R_ERROR;
801 std::shared_ptr<pcp::ResultParcelable> return_parcel(
802 std::static_pointer_cast<pcp::ResultParcelable>(ptr));
804 auto pkgid_list = return_parcel->GetResult();
805 std::map<std::string, std::string> result_map;
806 for (auto& pkgid : pkgid_list)
807 result_map.insert(make_pair(pkgid.front(), pkgid.back()));
809 auto l_iter = result_map.find(l_appid);
810 if (l_iter == result_map.end()) {
811 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
812 << " for uid " << uid;
813 return PMINFO_R_ENOENT;
815 auto r_iter = result_map.find(r_appid);
816 if (r_iter == result_map.end()) {
817 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
818 << " for uid " << uid;
819 return PMINFO_R_ENOENT;
822 const char* l_pkgid = l_iter->second.c_str();
823 const char* r_pkgid = r_iter->second.c_str();
825 return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
828 extern "C" EXPORT_API int _parser_execute_write_query(
829 int query_index, const char** query_args, unsigned int arg_cnt, uid_t uid) {
830 std::vector<std::string> args;
832 for (unsigned int i = 0; i < arg_cnt; i++) {
834 args.push_back(query_args[i]);
839 std::shared_ptr<pcp::AbstractParcelable> parcelable(
840 new pcp::QueryParcelable(uid, { query_index, std::move(args) },
841 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
842 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
844 pkgmgr_client::PkgInfoClient client(parcelable, uid,
845 pkgmgr_common::ReqType::QUERY);
846 if (!client.SendRequest())
849 auto ptr = client.GetResultParcel();
850 if (ptr == nullptr) {
851 LOG(ERROR) << "Fail to get return parcelable";
855 if (ptr->GetRequestResult() != PMINFO_R_OK) {
856 LOG(ERROR) << "Request fail";
860 if (ptr->GetType() != pcp::ParcelableType::Result) {
861 LOG(ERROR) << "Invalid parcelable type";
867 extern "C" EXPORT_API int _parser_execute_write_queries(
868 int query_index, const char*** query_args, unsigned int arg_cnt,
869 unsigned int query_cnt, uid_t uid) {
870 std::vector<std::pair<int, std::vector<std::string>>> queries;
872 for (unsigned int i = 0; i < query_cnt; i++) {
873 std::vector<std::string> args;
874 for (unsigned int j = 0; j < arg_cnt; j++) {
875 if (query_args[i][j])
876 args.push_back(query_args[i][j]);
880 queries.push_back({ query_index, std::move(args) });
883 std::shared_ptr<pcp::AbstractParcelable> parcelable(
884 new pcp::QueryParcelable(uid, std::move(queries),
885 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
886 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
888 pkgmgr_client::PkgInfoClient client(parcelable, uid,
889 pkgmgr_common::ReqType::QUERY);
890 if (!client.SendRequest())
893 auto ptr = client.GetResultParcel();
894 if (ptr == nullptr) {
895 LOG(ERROR) << "Fail to get return parcelable";
899 if (ptr->GetRequestResult() != PMINFO_R_OK) {
900 LOG(ERROR) << "Request fail";
904 if (ptr->GetType() != pcp::ParcelableType::Result) {
905 LOG(ERROR) << "Invalid parcelable type";
912 extern "C" EXPORT_API int _parser_insert_manifest_info(
913 manifest_x* mfx, uid_t uid) {
915 std::make_shared<pcp::PkgInfoParcelable>(uid,
916 std::vector<package_x*>{mfx}, WriteType::Insert, false);
918 pkgmgr_client::PkgInfoClient client(parcelable, uid,
919 pkgmgr_common::ReqType::SET_PKG_INFO);
920 if (!client.SendRequest())
923 auto ptr = client.GetResultParcel();
924 if (ptr == nullptr) {
925 LOG(ERROR) << "Fail to get return parcelable";
929 if (ptr->GetRequestResult() != PMINFO_R_OK) {
930 LOG(ERROR) << "Request fail";
934 if (ptr->GetType() != pcp::ParcelableType::Result) {
935 LOG(ERROR) << "Invalid parcelable type";
942 extern "C" EXPORT_API int _parser_update_manifest_info(
943 manifest_x* mfx, uid_t uid) {
945 std::make_shared<pcp::PkgInfoParcelable>(uid,
946 std::vector<package_x*>{mfx}, WriteType::Update, false);
948 pkgmgr_client::PkgInfoClient client(parcelable, uid,
949 pkgmgr_common::ReqType::SET_PKG_INFO);
950 if (!client.SendRequest())
953 auto ptr = client.GetResultParcel();
954 if (ptr == nullptr) {
955 LOG(ERROR) << "Fail to get return parcelable";
959 if (ptr->GetRequestResult() != PMINFO_R_OK) {
960 LOG(ERROR) << "Request fail";
964 if (ptr->GetType() != pcp::ParcelableType::Result) {
965 LOG(ERROR) << "Invalid parcelable type";
972 extern "C" EXPORT_API int _parser_delete_manifest_info(
973 manifest_x* mfx, uid_t uid) {
975 std::make_shared<pcp::PkgInfoParcelable>(uid,
976 std::vector<package_x*>{mfx}, WriteType::Delete, false);
978 pkgmgr_client::PkgInfoClient client(parcelable, uid,
979 pkgmgr_common::ReqType::SET_PKG_INFO);
980 if (!client.SendRequest())
983 auto ptr = client.GetResultParcel();
984 if (ptr == nullptr) {
985 LOG(ERROR) << "Fail to get return parcelable";
989 if (ptr->GetRequestResult() != PMINFO_R_OK) {
990 LOG(ERROR) << "Request fail";
994 if (ptr->GetType() != pcp::ParcelableType::Result) {
995 LOG(ERROR) << "Invalid parcelable type";
1002 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1003 pkgmgr_certinfo_x* cert, uid_t uid) {
1004 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1005 new pcp::CertInfoParcelable(uid, cert, false));
1006 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1007 pkgmgr_common::ReqType::SET_CERT_INFO);
1009 if (!client.SendRequest())
1010 return PMINFO_R_ERROR;
1012 auto ptr = client.GetResultParcel();
1013 if (ptr == nullptr) {
1014 LOG(ERROR) << "Fail to get return parcelable";
1015 return PMINFO_R_ERROR;
1018 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1019 LOG(ERROR) << "Request fail";
1020 return ptr->GetRequestResult();
1023 if (ptr->GetType() != pcp::ParcelableType::Result) {
1024 LOG(ERROR) << "Invalid parcelable type";
1025 return PMINFO_R_ERROR;
1031 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char* pkgid,
1032 pkgmgr_certinfo_x* cert, uid_t uid) {
1033 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1034 new pcp::CertInfoParcelable(uid,
1035 std::string(pkgid)));
1037 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1038 pkgmgr_common::ReqType::GET_CERT_INFO);
1039 if (!client.SendRequest())
1040 return PMINFO_R_ERROR;
1042 auto ptr = client.GetResultParcel();
1043 if (ptr == nullptr) {
1044 LOG(ERROR) << "Fail to get return parcelable";
1045 return PMINFO_R_ERROR;
1048 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1049 LOG(ERROR) << "Request fail";
1050 return ptr->GetRequestResult();
1053 if (ptr->GetType() != pcp::ParcelableType::CertInfo) {
1054 LOG(ERROR) << "Invalid parcelable type";
1055 return PMINFO_R_ERROR;
1058 std::shared_ptr<pcp::CertInfoParcelable> return_parcel(
1059 std::static_pointer_cast<pcp::CertInfoParcelable>(ptr));
1061 pkgmgr_certinfo_x* certinfo = return_parcel->ExtractCertInfo();
1062 if (certinfo == nullptr)
1063 return PMINFO_R_ERROR;
1065 cert->for_all_users = certinfo->for_all_users;
1066 cert->pkgid = certinfo->pkgid;
1067 certinfo->pkgid = nullptr;
1068 cert->cert_value = certinfo->cert_value;
1069 certinfo->cert_value = nullptr;
1070 for (int i = 0; i < MAX_CERT_TYPE; i++) {
1071 cert->cert_info[i] = certinfo->cert_info[i];
1072 certinfo->cert_info[i] = nullptr;
1074 for (int i = 0; i < MAX_CERT_TYPE; i++)
1075 cert->cert_id[i] = certinfo->cert_id[i];
1082 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char* pkgid) {
1083 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1084 new pcp::QueryParcelable(0,
1085 { QUERY_INDEX_PKGINFO_DELETE_CERTINFO, { pkgid } },
1086 pcd::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1087 pcd::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1089 pkgmgr_client::PkgInfoClient client(parcelable, 0,
1090 pkgmgr_common::ReqType::QUERY);
1091 if (!client.SendRequest())
1092 return PMINFO_R_ERROR;
1094 auto ptr = client.GetResultParcel();
1095 if (ptr == nullptr) {
1096 LOG(ERROR) << "Fail to get return parcelable";
1097 return PMINFO_R_ERROR;
1100 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1101 LOG(ERROR) << "Request fail";
1102 return PMINFO_R_ERROR;
1105 if (ptr->GetType() != pcp::ParcelableType::Result) {
1106 LOG(ERROR) << "Invalid parcelable type";
1107 return PMINFO_R_ERROR;
1113 extern "C" EXPORT_API int _parser_clear_cache_memory_db(uid_t uid) {
1114 std::shared_ptr<pcp::AbstractParcelable> parcelable(
1115 new pcp::CommandParcelable(uid, CommandType::RemoveCache));
1117 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1118 pkgmgr_common::ReqType::COMMAND);
1120 if (!client.SendRequest())
1121 return PMINFO_R_ERROR;
1123 auto ptr = client.GetResultParcel();
1124 if (ptr == nullptr) {
1125 LOG(ERROR) << "Fail to get return parcelable";
1126 return PMINFO_R_ERROR;
1129 if (ptr->GetRequestResult() != PMINFO_R_OK) {
1130 LOG(ERROR) << "Request fail";
1131 return PMINFO_R_ERROR;
1134 if (ptr->GetType() != pcp::ParcelableType::Result) {
1135 LOG(ERROR) << "Invalid parcelable type";
1136 return PMINFO_R_ERROR;