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>
27 #include "pkgmgr_parser.h"
28 #include "pkgmgrinfo_private.h"
31 #include "common/database/abstract_db_handler.hh"
32 #include "common/database/pkg_set_db_handler.hh"
33 #include "common/parcel/appinfo_parcelable.hh"
34 #include "common/parcel/certinfo_parcelable.hh"
35 #include "common/parcel/depinfo_parcelable.hh"
36 #include "common/parcel/filter_parcelable.hh"
37 #include "common/parcel/pkginfo_parcelable.hh"
38 #include "common/parcel/query_parcelable.hh"
39 #include "common/parcel/result_parcelable.hh"
41 #include "client/pkginfo_client.hh"
48 #define LOG_TAG "PKGMGR_INFO"
53 #define EXPORT_API __attribute__((visibility("default")))
55 extern "C" EXPORT_API int _pkginfo_get_packages(uid_t uid,
56 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
57 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
58 new pkgmgr_common::parcel::FilterParcelable(uid,
59 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
61 pkgmgr_client::PkgInfoClient client(parcelable, uid,
62 pkgmgr_common::ReqType::GET_PKG_INFO);
63 if (!client.SendRequest())
64 return PMINFO_R_ERROR;
66 std::shared_ptr<pkgmgr_common::parcel::PkgInfoParcelable> return_parcel(
67 std::static_pointer_cast<pkgmgr_common::parcel::PkgInfoParcelable>(
68 client.GetResultParcel()));
70 if (return_parcel == nullptr) {
71 LOG(ERROR) << "Fail to get return parcelable";
72 return PMINFO_R_ERROR;
75 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
76 LOG(ERROR) << "Request fail";
77 return return_parcel->GetRequestResult();
80 tizen_base::Parcel parcel;
81 parcel.ReadParcelable(return_parcel.get());
83 auto result_list = return_parcel->GetPkgInfo();
84 // TODO: check noentry error has returned if size of result_list is 0
85 for (auto& pkginfo : result_list)
86 g_hash_table_insert(packages, (gpointer)pkginfo->package,
92 extern "C" EXPORT_API int _pkginfo_get_depends_on(uid_t uid,
93 const char *pkgid, GList **dependencies) {
94 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
95 new pkgmgr_common::parcel::DepInfoParcelable(std::string(pkgid)));
97 pkgmgr_client::PkgInfoClient client(parcelable, uid,
98 pkgmgr_common::ReqType::GET_PKG_DEP_INFO);
99 if (!client.SendRequest())
100 return PMINFO_R_ERROR;
102 std::shared_ptr<pkgmgr_common::parcel::DepInfoParcelable> return_parcel(
103 std::static_pointer_cast<pkgmgr_common::parcel::DepInfoParcelable>(
104 client.GetResultParcel()));
106 if (return_parcel == nullptr) {
107 LOG(ERROR) << "Fail to get return parcelable";
108 return PMINFO_R_ERROR;
111 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
112 LOG(ERROR) << "Request fail";
113 return return_parcel->GetRequestResult();
116 tizen_base::Parcel parcel;
117 parcel.ReadParcelable(return_parcel.get());
119 auto dependency_list = return_parcel->GetDependencyInfo();
120 for (auto& dependency : dependency_list)
121 *dependencies = g_list_prepend(*dependencies, dependency);
125 // TODO: Need to add target db uid to identify which database to be searched
126 extern "C" EXPORT_API int _appinfo_get_applications(uid_t db_uid, uid_t uid,
127 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) {
128 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
129 new pkgmgr_common::parcel::FilterParcelable(uid,
130 static_cast<pkgmgrinfo_filter_x*>(filter), flag));
132 pkgmgr_client::PkgInfoClient client(parcelable, uid, pkgmgr_common::ReqType::GET_APP_INFO);
133 if (!client.SendRequest())
134 return PMINFO_R_ERROR;
136 std::shared_ptr<pkgmgr_common::parcel::AppInfoParcelable> return_parcel(
137 std::static_pointer_cast<pkgmgr_common::parcel::AppInfoParcelable>(
138 client.GetResultParcel()));
140 if (return_parcel == nullptr) {
141 LOG(ERROR) << "Fail to get return parcelable";
142 return PMINFO_R_ERROR;
145 int ret = return_parcel->GetRequestResult();
146 if (ret != PMINFO_R_OK) {
147 if (ret == PMINFO_R_ENOENT) {
148 LOG(DEBUG) << "No such application";
150 LOG(ERROR) << "Request fail";
155 tizen_base::Parcel parcel;
156 parcel.ReadParcelable(return_parcel.get());
157 auto result_list = return_parcel->GetAppInfo();
158 for (auto& appinfo : result_list)
159 g_hash_table_insert(packages, (gpointer)appinfo->appid,
165 extern "C" EXPORT_API char *_appinfo_get_localed_label(
166 const char *appid, const char *locale, uid_t uid) {
167 char *query = nullptr;
168 query = sqlite3_mprintf(
169 "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
170 "WHERE app_id=%Q AND app_locale=%Q),"
171 "(SELECT app_label FROM package_app_localized_info WHERE "
172 "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
173 if (query == nullptr) {
174 LOG(ERROR) << "Out of memory";
178 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
179 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
180 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
181 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
183 pkgmgr_client::PkgInfoClient client(parcelable, uid,
184 pkgmgr_common::ReqType::QUERY);
185 if (!client.SendRequest()) {
190 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
191 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
192 client.GetResultParcel()));
194 if (return_parcel == nullptr) {
195 LOG(ERROR) << "Fail to get return parcelable";
199 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
200 LOG(ERROR) << "Request fail";
204 tizen_base::Parcel parcel;
205 parcel.ReadParcelable(return_parcel.get());
207 // result_list is vector of string vector
208 char *label = nullptr;
209 auto result_list = return_parcel->GetResult();
210 for (auto result : result_list) {
211 // result is string vector
212 // it only has one string or not.
213 if (result.front().empty() || result.front().length() == 0)
215 label = strdup(result.front().c_str());
216 if (label == nullptr) {
217 LOG(ERROR) << "Out of memory";
226 extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
227 const char *providerid, const char *type, uid_t uid,
228 char **appid, char **access) {
229 char *query = nullptr;
230 query = sqlite3_mprintf("SELECT app_id, access FROM "
231 "package_app_data_control WHERE "
232 "providerid=%Q AND type=%Q", providerid, type);
233 if (query == nullptr) {
234 LOG(ERROR) << "Out of memory";
235 return PMINFO_R_ERROR;
238 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
239 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
240 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
241 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
243 pkgmgr_client::PkgInfoClient client(parcelable, uid,
244 pkgmgr_common::ReqType::QUERY);
245 if (!client.SendRequest()) {
247 return PMINFO_R_ERROR;
250 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
251 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
252 client.GetResultParcel()));
254 if (return_parcel == nullptr) {
255 LOG(ERROR) << "Fail to get return parcelable";
256 return PMINFO_R_ERROR;
259 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
260 LOG(ERROR) << "Request fail";
261 return return_parcel->GetRequestResult();
264 tizen_base::Parcel parcel;
265 parcel.ReadParcelable(return_parcel.get());
267 // result_list is vector of string vector
268 auto result_list = return_parcel->GetResult();
269 if (result_list.size() == 0)
270 return PMINFO_R_ENOENT;
271 for (auto result : result_list) {
272 if (result.size() != 2)
273 return PMINFO_R_ERROR;
274 if (result.front().empty() || result.front().size() == 0 ||
275 result.back().empty() || result.back().size() == 0)
276 return PMINFO_R_ERROR;
277 *appid = strdup(result.front().c_str());
278 *access = strdup(result.back().c_str());
279 if (*appid == nullptr || *access == nullptr) {
280 LOG(ERROR) << "Out of memory";
281 return PMINFO_R_ERROR;
288 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
289 const char *providerid, uid_t uid, char **appid) {
290 char *query = nullptr;
292 query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
293 "WHERE providerid=%Q", providerid);
294 if (query == nullptr) {
295 LOGE("Out of memory");
296 return PMINFO_R_ERROR;
298 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
299 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
300 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
301 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
303 pkgmgr_client::PkgInfoClient client(parcelable, uid,
304 pkgmgr_common::ReqType::QUERY);
305 if (!client.SendRequest()) {
307 return PMINFO_R_ERROR;
309 // TODO: deliver rawdata to reqhandler directly if server is not working
311 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
312 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
313 client.GetResultParcel()));
315 if (return_parcel == nullptr) {
316 LOG(ERROR) << "Fail to get return parcelable";
317 return PMINFO_R_ERROR;
320 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
321 LOG(ERROR) << "Request fail";
322 return return_parcel->GetRequestResult();
325 tizen_base::Parcel parcel;
326 parcel.ReadParcelable(return_parcel.get());
329 // result_list is vector of string vector
330 auto result_list = return_parcel->GetResult();
331 if (result_list.size() == 0)
332 return PMINFO_R_ENOENT;
333 for (auto result : result_list) {
334 if (result.size() != 1)
335 return PMINFO_R_ERROR;
336 if (result.front().empty() || result.front().size() == 0)
337 return PMINFO_R_ERROR;
338 *appid = strdup(result.front().c_str());
339 if (*appid == nullptr) {
340 LOG(ERROR) << "Out of memory";
341 return PMINFO_R_ERROR;
348 extern "C" EXPORT_API int _appinfo_get_datacontrol_trusted_info(
349 const char *providerid, const char *type, uid_t uid,
350 char **appid, char **trusted) {
351 char *query = nullptr;
352 query = sqlite3_mprintf(
353 "SELECT app_id, trusted FROM package_app_data_control "
354 "WHERE providerid=%Q AND type=%Q", providerid, type);
355 if (query == nullptr) {
356 LOGE("Out of memory");
357 return PMINFO_R_ERROR;
360 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
361 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
362 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
363 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
365 pkgmgr_client::PkgInfoClient client(parcelable, uid,
366 pkgmgr_common::ReqType::QUERY);
367 if (!client.SendRequest()) {
369 return PMINFO_R_ERROR;
371 // TODO: deliver rawdata to reqhandler directly if server is not working
373 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
374 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
375 client.GetResultParcel()));
377 if (return_parcel == nullptr) {
378 LOG(ERROR) << "Fail to get return parcelable";
379 return PMINFO_R_ERROR;
382 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
383 LOG(ERROR) << "Request fail";
384 return return_parcel->GetRequestResult();
387 tizen_base::Parcel parcel;
388 parcel.ReadParcelable(return_parcel.get());
390 // result_list is vector of string vector
391 auto result_list = return_parcel->GetResult();
392 if (result_list.size() == 0)
393 return PMINFO_R_ENOENT;
394 for (auto result : result_list) {
395 if (result.size() != 2)
396 return PMINFO_R_ERROR;
397 if (result.front().empty() || result.front().size() == 0 ||
398 result.back().empty() || result.back().size() == 0)
399 return PMINFO_R_ERROR;
400 *appid = strdup(result.front().c_str());
401 *trusted = strdup(result.back().c_str());
402 if (*appid == nullptr || *trusted == nullptr) {
403 LOG(ERROR) << "Out of memory";
404 return PMINFO_R_ERROR;
411 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
412 const char *providerid, const char *type, uid_t uid,
413 GList **privileges) {
414 char *query = nullptr;
415 query = sqlite3_mprintf(
416 "SELECT privilege FROM package_app_data_control_privilege "
417 "WHERE providerid=%Q AND type=%Q", providerid, type);
418 if (query == nullptr) {
419 LOGE("Out of memory");
420 return PMINFO_R_ERROR;
423 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
424 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
425 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
426 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
428 pkgmgr_client::PkgInfoClient client(parcelable, uid,
429 pkgmgr_common::ReqType::QUERY);
430 if (!client.SendRequest()) {
432 return PMINFO_R_ERROR;
434 // TODO: deliver rawdata to reqhandler directly if server is not working
436 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
437 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
438 client.GetResultParcel()));
440 if (return_parcel == nullptr) {
441 LOG(ERROR) << "Fail to get return parcelable";
442 return PMINFO_R_ERROR;
445 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
446 LOG(ERROR) << "Request fail";
447 return return_parcel->GetRequestResult();
450 tizen_base::Parcel parcel;
451 parcel.ReadParcelable(return_parcel.get());
453 // result_list is vector of string vector
454 auto result_list = return_parcel->GetResult();
455 if (result_list.size() == 0)
456 return PMINFO_R_ENOENT;
458 for (auto result : result_list) {
459 if (result.size() != 1)
460 return PMINFO_R_ERROR;
461 if (result.front().empty() || result.front().size() == 0)
462 return PMINFO_R_ERROR;
463 char *privilege = strdup(result.front().c_str());
464 if (privilege == nullptr) {
465 LOG(ERROR) << "Out of memory";
466 return PMINFO_R_ERROR;
468 *privileges = g_list_append(*privileges, privilege);
474 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
475 const char *appid, const char *operation, uid_t uid, GList **privileges) {
476 char *query = nullptr;
477 query = sqlite3_mprintf(
478 "SELECT app_control, privilege FROM package_app_app_control_privilege "
479 "WHERE app_id=%Q", appid);
480 if (query == nullptr) {
481 LOG(ERROR) << "Out of memory";
482 return PMINFO_R_ERROR;
485 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
486 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
487 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
488 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
490 pkgmgr_client::PkgInfoClient client(parcelable, uid,
491 pkgmgr_common::ReqType::QUERY);
492 if (!client.SendRequest()) {
494 return PMINFO_R_ERROR;
496 // TODO: deliver rawdata to reqhandler directly if server is not working
498 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
499 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
500 client.GetResultParcel()));
502 if (return_parcel == nullptr) {
503 LOG(ERROR) << "Fail to get return parcelable";
504 return PMINFO_R_ERROR;
507 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
508 LOG(ERROR) << "Request fail";
509 return return_parcel->GetRequestResult();
512 tizen_base::Parcel parcel;
513 parcel.ReadParcelable(return_parcel.get());
515 // result_list is vector of string vector
516 auto result_list = return_parcel->GetResult();
517 if (result_list.size() == 0)
518 return PMINFO_R_ENOENT;
520 for (auto result : result_list) {
521 if (result.size() != 2)
522 return PMINFO_R_ERROR;
523 if (result.front().empty() || result.front().size() == 0 ||
524 result.back().empty() || result.back().size() == 0)
525 return PMINFO_R_ERROR;
526 std::string app_control = result.front();
527 std::stringstream ss(app_control);
529 while (std::getline(ss, token, '|')) {
530 if (token.compare(std::string(operation))) {
531 char *privilege = strdup(result.back().c_str());
532 if (privilege == nullptr) {
533 LOG(ERROR) << "Out of memory";
534 return PMINFO_R_ERROR;
536 *privileges = g_list_append(*privileges, privilege);
543 extern "C" EXPORT_API int _plugininfo_get_appids(
544 const char *pkgid, const char *plugin_type,
545 const char *plugin_name, GList **list) {
546 if (!pkgid || !plugin_type || !plugin_name || !list) {
547 LOG(ERROR) << "Invalid parameter";
548 return PMINFO_R_EINVAL;
551 char *query = nullptr;
552 query = sqlite3_mprintf(
554 "package_plugin_info WHERE pkgid=%Q AND "
555 "plugin_type=%Q AND plugin_name=%Q",
556 pkgid, plugin_type, plugin_name);
557 if (query == nullptr) {
558 LOG(ERROR) << "Out of memory";
559 return PMINFO_R_ERROR;
562 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
563 new pkgmgr_common::parcel::QueryParcelable(_getuid(), std::string(query),
564 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
565 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
568 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
569 pkgmgr_common::ReqType::QUERY);
570 if (!client.SendRequest()) {
571 return PMINFO_R_ERROR;
574 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
575 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
576 client.GetResultParcel()));
578 if (return_parcel == nullptr) {
579 LOG(ERROR) << "Fail to get return parcelable";
580 return PMINFO_R_ERROR;
583 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
584 LOG(ERROR) << "Request fail";
585 return return_parcel->GetRequestResult();
588 if (return_parcel->GetCol() != 1) {
589 LOG(ERROR) << "Invalid result";
590 return PMINFO_R_ERROR;
592 // result_list is vector of string vector
593 auto& result_list = return_parcel->GetResult();
594 if (result_list.size() == 0)
595 return PMINFO_R_ENOENT;
597 for (auto result : result_list) {
598 if (result.size() != 1) {
599 LOG(ERROR) << "Invalid result";
600 g_list_free_full(*list, free);
601 return PMINFO_R_ERROR;
603 *list = g_list_append(*list, strdup(result[0].c_str()));
609 static int __convert_update_type(const char *type, pkgmgrinfo_updateinfo_update_type *convert_type)
611 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
612 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
613 *convert_type = PMINFO_UPDATEINFO_NONE;
614 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
615 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
616 *convert_type = PMINFO_UPDATEINFO_FORCE;
617 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
618 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
619 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
625 static void __free_update_info(gpointer data)
627 updateinfo_x *update_info = (updateinfo_x *)data;
628 if (update_info == nullptr)
631 if (update_info->pkgid)
632 free((void *)update_info->pkgid);
633 if (update_info->version)
634 free((void *)update_info->version);
635 free((void *)update_info);
639 extern "C" EXPORT_API int _get_pkg_updateinfo(const char *pkgid,
640 GSList **update_info_list, uid_t uid)
642 char *query = nullptr;
645 if (pkgid == nullptr)
646 query = sqlite3_mprintf(
647 "SELECT package, update_version, update_type "
648 "FROM package_update_info");
650 query = sqlite3_mprintf(
651 "SELECT package, update_version, update_type "
652 "FROM package_update_info WHERE package=%Q",
654 if (query == nullptr) {
655 LOG(ERROR) << "Out of memory";
656 return PMINFO_R_ERROR;
659 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
660 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
661 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
662 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
665 pkgmgr_client::PkgInfoClient client(parcelable, uid,
666 pkgmgr_common::ReqType::QUERY);
667 if (!client.SendRequest()) {
668 return PMINFO_R_ERROR;
671 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
672 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
673 client.GetResultParcel()));
675 if (return_parcel == nullptr) {
676 LOG(ERROR) << "Fail to get return parcelable";
677 return PMINFO_R_ERROR;
680 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
681 LOG(ERROR) << "Request fail";
682 return return_parcel->GetRequestResult();
685 if (return_parcel->GetCol() != 3) {
686 LOG(ERROR) << "Invalid result";
687 return PMINFO_R_ERROR;
690 auto result_list = return_parcel->GetResult();
691 if (result_list.size() == 0)
692 return PMINFO_R_ENOENT;
694 for (auto result : result_list) {
695 if (result.size() != 3) {
696 LOG(ERROR) << "Invalid result";
697 g_slist_free_full(*update_info_list, __free_update_info);
698 return PMINFO_R_ERROR;
700 updateinfo_x *update_info = reinterpret_cast<updateinfo_x *>(calloc(1, sizeof(updateinfo_x)));
701 if (update_info == nullptr) {
702 LOG(ERROR) << "Out of memory";
703 return PMINFO_R_ERROR;
705 update_info->pkgid = strdup(result[0].c_str());
706 update_info->version = strdup(result[1].c_str());
707 pkgmgrinfo_updateinfo_update_type convert_type;
708 ret = __convert_update_type(result[2].c_str(), &convert_type);
710 __free_update_info(update_info);
711 g_slist_free_full(*update_info_list, __free_update_info);
712 return PMINFO_R_ERROR;
714 update_info->type = static_cast<int>(convert_type);
715 *update_info_list = g_slist_prepend(*update_info_list,
722 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char *pkgid,
723 INSTALL_LOCATION location, const char *external_pkg_path,
726 char *query = nullptr;
727 const char *location_str;
728 std::vector<std::string> queries;
730 if (location == INSTALL_INTERNAL)
731 location_str = "installed_internal";
732 else if (location == INSTALL_EXTERNAL)
733 location_str = "installed_external";
735 location_str = "installed_extended";
736 /* pkgcakge_info table */
737 query = sqlite3_mprintf(
738 "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
739 location_str, external_pkg_path, pkgid);
740 queries.emplace_back(query);
743 /* package_app_info table */
744 query = sqlite3_mprintf(
745 "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
746 location_str, external_pkg_path, pkgid);
747 queries.emplace_back(query);
750 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
751 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
752 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
753 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
755 pkgmgr_client::PkgInfoClient client(parcelable, uid,
756 pkgmgr_common::ReqType::QUERY);
757 if (!client.SendRequest()) {
758 return PMINFO_R_ERROR;
761 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
762 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
763 client.GetResultParcel()));
765 if (return_parcel == nullptr) {
766 LOG(ERROR) << "Fail to get return parcelable";
767 return PMINFO_R_ERROR;
770 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
771 LOG(ERROR) << "Request fail";
772 return return_parcel->GetRequestResult();
775 auto result_list = return_parcel->GetResult();
776 if (result_list.size() != 1) {
777 LOG(ERROR) << "Invalid result";
778 return PMINFO_R_ERROR;
781 if (result_list[0].size() != 1) {
782 LOG(ERROR) << "Invalid result";
783 return PMINFO_R_ERROR;
786 LOG(ERROR) << "result : " << result_list[0][0];
787 if (result_list[0][0] != "SUCCESS")
788 return PMINFO_R_ERROR;
793 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char *l_pkgid,
794 const char *r_pkgid, pkgmgrinfo_cert_compare_result_type_e *result) {
795 char *query = sqlite3_mprintf("SELECT package, "
796 "COALESCE(author_signer_cert, -1) FROM package_cert_info WHERE "
797 "package IN (%Q, %Q)", l_pkgid, r_pkgid);
798 if (query == nullptr) {
799 LOG(ERROR) << "Out of memory";
800 return PMINFO_R_ERROR;
802 std::vector<std::string> queries;
803 queries.emplace_back(query);
806 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
807 new pkgmgr_common::parcel::QueryParcelable(0, queries,
808 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
809 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
810 pkgmgr_client::PkgInfoClient client(parcelable, 0,
811 pkgmgr_common::ReqType::QUERY);
812 if (!client.SendRequest()) {
813 return PMINFO_R_ERROR;
816 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
817 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
818 client.GetResultParcel()));
820 if (return_parcel == nullptr) {
821 LOG(ERROR) << "Fail to get return parcelable";
822 return PMINFO_R_ERROR;
825 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
826 LOG(ERROR) << "Request fail";
827 return return_parcel->GetRequestResult();
830 auto certinfo_list = return_parcel->GetResult();
831 if (certinfo_list.size() != 2)
832 return PMINFO_R_ERROR;
834 std::map<std::string, std::string> result_map;
835 for (auto& certinfo : certinfo_list)
836 result_map.insert(make_pair(certinfo.front(), certinfo.back()));
838 if (result_map.find(std::string(l_pkgid))->second == "-1" &&
839 result_map.find(std::string(r_pkgid))->second == "-1")
840 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
841 else if (result_map.find(std::string(l_pkgid))->second == "-1")
842 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
843 else if (result_map.find(std::string(r_pkgid))->second == "-1")
844 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
845 else if (result_map.find(std::string(l_pkgid))->second ==
846 result_map.find(std::string(r_pkgid))->second)
847 *result = PMINFO_CERT_COMPARE_MATCH;
849 *result = PMINFO_CERT_COMPARE_MISMATCH;
854 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
855 const char *l_appid, const char *r_appid,
856 pkgmgrinfo_cert_compare_result_type_e *result) {
857 char* query = sqlite3_mprintf("SELECT app_id, package FROM "
858 "package_app_info WHERE app_id IN (%Q, %Q)", l_appid, r_appid);
859 if (query == nullptr) {
860 LOG(ERROR) << "Out of memory";
861 return PMINFO_R_ERROR;
863 std::vector<std::string> queries;
864 queries.emplace_back(query);
867 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
868 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
869 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
870 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
871 pkgmgr_client::PkgInfoClient client(parcelable, uid,
872 pkgmgr_common::ReqType::QUERY);
873 if (!client.SendRequest()) {
874 return PMINFO_R_ERROR;
877 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
878 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
879 client.GetResultParcel()));
881 if (return_parcel == nullptr) {
882 LOG(ERROR) << "Fail to get return parcelable";
883 return PMINFO_R_ERROR;
886 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
887 LOG(ERROR) << "Request fail";
888 return return_parcel->GetRequestResult();
891 auto pkgid_list = return_parcel->GetResult();
892 std::map<std::string, std::string> result_map;
893 for (auto& pkgid : pkgid_list)
894 result_map.insert(make_pair(pkgid.front(), pkgid.back()));
896 if (result_map.find(std::string(l_appid)) == result_map.end()) {
897 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
898 << " for uid " << uid;
899 return PMINFO_R_ENOENT;
900 } else if (result_map.find(std::string(r_appid)) == result_map.end()) {
901 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
902 << " for uid " << uid;
903 return PMINFO_R_ENOENT;
906 const char* l_pkgid = result_map.find(
907 std::string(l_appid))->second.c_str();
908 const char* r_pkgid = result_map.find(
909 std::string(r_appid))->second.c_str();
911 return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
914 extern "C" EXPORT_API int _parser_execute_write_query(const char *query, uid_t uid)
916 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
917 new pkgmgr_common::parcel::QueryParcelable(uid, query,
918 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
919 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
921 pkgmgr_client::PkgInfoClient client(parcelable, uid,
922 pkgmgr_common::ReqType::QUERY);
923 if (!client.SendRequest()) {
927 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
928 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
929 client.GetResultParcel()));
931 if (return_parcel == nullptr) {
932 LOG(ERROR) << "Fail to get return parcelable";
936 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
937 LOG(ERROR) << "Request fail";
941 auto result_list = return_parcel->GetResult();
942 if (result_list.size() != 1) {
943 LOG(ERROR) << "Invalid result";
947 if (result_list[0].size() != 1) {
948 LOG(ERROR) << "Invalid result";
952 LOG(ERROR) << "result : " << result_list[0][0];
953 if (result_list[0][0] != "SUCCESS")
959 extern "C" EXPORT_API int _parser_execute_write_queries(const char **queries, int len, uid_t uid)
961 std::vector<std::string> query_vt;
962 for (int i = 0; i < len; ++i)
963 query_vt.emplace_back(queries[i]);
965 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
966 new pkgmgr_common::parcel::QueryParcelable(uid, query_vt,
967 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
968 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
970 pkgmgr_client::PkgInfoClient client(parcelable, uid,
971 pkgmgr_common::ReqType::QUERY);
972 if (!client.SendRequest()) {
976 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
977 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
978 client.GetResultParcel()));
980 if (return_parcel == nullptr) {
981 LOG(ERROR) << "Fail to get return parcelable";
985 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
986 LOG(ERROR) << "Request fail";
990 auto result_list = return_parcel->GetResult();
991 if (result_list.size() != 1) {
992 LOG(ERROR) << "Invalid result";
996 if (result_list[0].size() != 1) {
997 LOG(ERROR) << "Invalid result";
1001 LOG(ERROR) << "result : " << result_list[0][0];
1002 if (result_list[0][0] != "SUCCESS")
1008 extern "C" EXPORT_API int _parser_insert_manifest_info(manifest_x *mfx, uid_t uid)
1010 std::vector<package_x *> vt { mfx };
1012 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1013 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Insert));
1015 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1016 pkgmgr_common::ReqType::SET_PKG_INFO);
1017 if (!client.SendRequest()) {
1021 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1022 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1023 client.GetResultParcel()));
1025 if (return_parcel == nullptr) {
1026 LOG(ERROR) << "Fail to get return parcelable";
1030 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1031 LOG(ERROR) << "Request fail";
1038 extern "C" EXPORT_API int _parser_update_manifest_info(manifest_x *mfx, uid_t uid)
1040 std::vector<package_x *> vt { mfx };
1042 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1043 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Update));
1045 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1046 pkgmgr_common::ReqType::SET_PKG_INFO);
1047 if (!client.SendRequest()) {
1051 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1052 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1053 client.GetResultParcel()));
1055 if (return_parcel == nullptr) {
1056 LOG(ERROR) << "Fail to get return parcelable";
1060 if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1061 LOG(ERROR) << "Request fail";
1068 extern "C" EXPORT_API int _parser_delete_manifest_info(manifest_x *mfx, uid_t uid)
1070 std::vector<package_x *> vt { mfx };
1072 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1073 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Delete));
1075 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1076 pkgmgr_common::ReqType::SET_PKG_INFO);
1077 if (!client.SendRequest()) {
1081 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1082 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1083 client.GetResultParcel()));
1085 if (return_parcel == nullptr) {
1086 LOG(ERROR) << "Fail to get return parcelable";
1090 if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1091 LOG(ERROR) << "Request fail";
1098 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1099 pkgmgr_certinfo_x* cert, uid_t uid)
1101 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1102 new pkgmgr_common::parcel::CertInfoParcelable(uid, cert));
1104 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1105 pkgmgr_common::ReqType::SET_CERT_INFO);
1106 if (!client.SendRequest())
1107 return PMINFO_R_ERROR;
1109 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1110 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1111 client.GetResultParcel()));
1113 if (return_parcel == nullptr) {
1114 LOG(ERROR) << "Fail to get return parcelable";
1115 return PMINFO_R_ERROR;
1118 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1119 LOG(ERROR) << "Request fail";
1120 return return_parcel->GetRequestResult();
1126 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char *pkgid,
1127 pkgmgr_certinfo_x** cert, uid_t uid)
1129 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1130 new pkgmgr_common::parcel::CertInfoParcelable(uid,
1131 std::string(pkgid)));
1133 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1134 pkgmgr_common::ReqType::GET_CERT_INFO);
1135 if (!client.SendRequest())
1136 return PMINFO_R_ERROR;
1138 std::shared_ptr<pkgmgr_common::parcel::CertInfoParcelable> return_parcel(
1139 std::static_pointer_cast<pkgmgr_common::parcel::CertInfoParcelable>(
1140 client.GetResultParcel()));
1142 if (return_parcel == nullptr) {
1143 LOG(ERROR) << "Fail to get return parcelable";
1144 return PMINFO_R_ERROR;
1147 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1148 LOG(ERROR) << "Request fail";
1149 return return_parcel->GetRequestResult();
1152 tizen_base::Parcel parcel;
1153 parcel.ReadParcelable(return_parcel.get());
1154 auto certinfo = return_parcel->GetCertInfo();
1155 if (certinfo == nullptr)
1156 return PMINFO_R_ERROR;
1158 *cert = (pkgmgr_certinfo_x*)certinfo;
1162 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char *pkgid)
1164 char* query = sqlite3_mprintf("UPDATE package_cert_info SET "
1165 "package_count = package_count - 1 WHERE package=%Q", pkgid);
1166 if (query == nullptr) {
1167 LOG(ERROR) << "Out of memory";
1168 return PMINFO_R_ERROR;
1171 std::vector<std::string> queries;
1172 queries.emplace_back(query);
1173 sqlite3_free(query);
1175 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1176 new pkgmgr_common::parcel::QueryParcelable(0, queries,
1177 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1178 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1180 pkgmgr_client::PkgInfoClient client(parcelable, 0,
1181 pkgmgr_common::ReqType::QUERY);
1182 if (!client.SendRequest()) {
1183 return PMINFO_R_ERROR;
1186 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1187 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1188 client.GetResultParcel()));
1190 if (return_parcel == nullptr) {
1191 LOG(ERROR) << "Fail to get return parcelable";
1192 return PMINFO_R_ERROR;
1195 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1196 LOG(ERROR) << "Request fail";
1197 return return_parcel->GetRequestResult();
1200 auto result_list = return_parcel->GetResult();
1201 if (result_list.size() != 1) {
1202 LOG(ERROR) << "Invalid result";
1203 return PMINFO_R_ERROR;
1206 if (result_list[0].size() != 1) {
1207 LOG(ERROR) << "Invalid result";
1208 return PMINFO_R_ERROR;
1211 LOG(ERROR) << "result : " << result_list[0][0];
1212 if (result_list[0][0] != "SUCCESS")
1213 return PMINFO_R_ERROR;