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 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
146 LOG(ERROR) << "Request fail";
147 return return_parcel->GetRequestResult();
150 tizen_base::Parcel parcel;
151 parcel.ReadParcelable(return_parcel.get());
152 auto result_list = return_parcel->GetAppInfo();
153 for (auto& appinfo : result_list)
154 g_hash_table_insert(packages, (gpointer)appinfo->appid,
160 extern "C" EXPORT_API char *_appinfo_get_localed_label(
161 const char *appid, const char *locale, uid_t uid) {
162 char *query = nullptr;
163 query = sqlite3_mprintf(
164 "SELECT COALESCE((SELECT app_label FROM package_app_localized_info "
165 "WHERE app_id=%Q AND app_locale=%Q),"
166 "(SELECT app_label FROM package_app_localized_info WHERE "
167 "app_id=%Q AND app_locale='No Locale'))", appid, locale, appid);
168 if (query == nullptr) {
169 LOG(ERROR) << "Out of memory";
173 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
174 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
175 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
176 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
178 pkgmgr_client::PkgInfoClient client(parcelable, uid,
179 pkgmgr_common::ReqType::QUERY);
180 if (!client.SendRequest()) {
185 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
186 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
187 client.GetResultParcel()));
189 if (return_parcel == nullptr) {
190 LOG(ERROR) << "Fail to get return parcelable";
194 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
195 LOG(ERROR) << "Request fail";
199 tizen_base::Parcel parcel;
200 parcel.ReadParcelable(return_parcel.get());
202 // result_list is vector of string vector
203 char *label = nullptr;
204 auto result_list = return_parcel->GetResult();
205 for (auto result : result_list) {
206 // result is string vector
207 // it only has one string or not.
208 if (result.front().empty() || result.front().length() == 0)
210 label = strdup(result.front().c_str());
211 if (label == nullptr) {
212 LOG(ERROR) << "Out of memory";
221 extern "C" EXPORT_API int _appinfo_get_datacontrol_info(
222 const char *providerid, const char *type, uid_t uid,
223 char **appid, char **access) {
224 char *query = nullptr;
225 query = sqlite3_mprintf("SELECT app_id, access FROM "
226 "package_app_data_control WHERE "
227 "providerid=%Q AND type=%Q", providerid, type);
228 if (query == nullptr) {
229 LOG(ERROR) << "Out of memory";
230 return PMINFO_R_ERROR;
233 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
234 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
235 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
236 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
238 pkgmgr_client::PkgInfoClient client(parcelable, uid,
239 pkgmgr_common::ReqType::QUERY);
240 if (!client.SendRequest()) {
242 return PMINFO_R_ERROR;
245 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
246 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
247 client.GetResultParcel()));
249 if (return_parcel == nullptr) {
250 LOG(ERROR) << "Fail to get return parcelable";
251 return PMINFO_R_ERROR;
254 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
255 LOG(ERROR) << "Request fail";
256 return return_parcel->GetRequestResult();
259 tizen_base::Parcel parcel;
260 parcel.ReadParcelable(return_parcel.get());
262 // result_list is vector of string vector
263 auto result_list = return_parcel->GetResult();
264 if (result_list.size() == 0)
265 return PMINFO_R_ENOENT;
266 for (auto result : result_list) {
267 if (result.size() != 2)
268 return PMINFO_R_ERROR;
269 if (result.front().empty() || result.front().size() == 0 ||
270 result.back().empty() || result.back().size() == 0)
271 return PMINFO_R_ERROR;
272 *appid = strdup(result.front().c_str());
273 *access = strdup(result.back().c_str());
274 if (*appid == nullptr || *access == nullptr) {
275 LOG(ERROR) << "Out of memory";
276 return PMINFO_R_ERROR;
283 extern "C" EXPORT_API int _appinfo_get_datacontrol_appid(
284 const char *providerid, uid_t uid, char **appid) {
285 char *query = nullptr;
287 query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
288 "WHERE providerid=%Q", providerid);
289 if (query == nullptr) {
290 LOGE("Out of memory");
291 return PMINFO_R_ERROR;
293 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
294 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
295 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
296 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
298 pkgmgr_client::PkgInfoClient client(parcelable, uid,
299 pkgmgr_common::ReqType::QUERY);
300 if (!client.SendRequest()) {
302 return PMINFO_R_ERROR;
304 // TODO: deliver rawdata to reqhandler directly if server is not working
306 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
307 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
308 client.GetResultParcel()));
310 if (return_parcel == nullptr) {
311 LOG(ERROR) << "Fail to get return parcelable";
312 return PMINFO_R_ERROR;
315 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
316 LOG(ERROR) << "Request fail";
317 return return_parcel->GetRequestResult();
320 tizen_base::Parcel parcel;
321 parcel.ReadParcelable(return_parcel.get());
324 // result_list is vector of string vector
325 auto result_list = return_parcel->GetResult();
326 if (result_list.size() == 0)
327 return PMINFO_R_ENOENT;
328 for (auto result : result_list) {
329 if (result.size() != 1)
330 return PMINFO_R_ERROR;
331 if (result.front().empty() || result.front().size() == 0)
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 char *query = nullptr;
347 query = sqlite3_mprintf(
348 "SELECT app_id, trusted FROM package_app_data_control "
349 "WHERE providerid=%Q AND type=%Q", providerid, type);
350 if (query == nullptr) {
351 LOGE("Out of memory");
352 return PMINFO_R_ERROR;
355 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
356 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
357 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
358 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
360 pkgmgr_client::PkgInfoClient client(parcelable, uid,
361 pkgmgr_common::ReqType::QUERY);
362 if (!client.SendRequest()) {
364 return PMINFO_R_ERROR;
366 // TODO: deliver rawdata to reqhandler directly if server is not working
368 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
369 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
370 client.GetResultParcel()));
372 if (return_parcel == nullptr) {
373 LOG(ERROR) << "Fail to get return parcelable";
374 return PMINFO_R_ERROR;
377 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
378 LOG(ERROR) << "Request fail";
379 return return_parcel->GetRequestResult();
382 tizen_base::Parcel parcel;
383 parcel.ReadParcelable(return_parcel.get());
385 // result_list is vector of string vector
386 auto result_list = return_parcel->GetResult();
387 if (result_list.size() == 0)
388 return PMINFO_R_ENOENT;
389 for (auto result : result_list) {
390 if (result.size() != 2)
391 return PMINFO_R_ERROR;
392 if (result.front().empty() || result.front().size() == 0 ||
393 result.back().empty() || result.back().size() == 0)
394 return PMINFO_R_ERROR;
395 *appid = strdup(result.front().c_str());
396 *trusted = strdup(result.back().c_str());
397 if (*appid == nullptr || *trusted == nullptr) {
398 LOG(ERROR) << "Out of memory";
399 return PMINFO_R_ERROR;
406 extern "C" EXPORT_API int _appinfo_get_datacontrol_privileges(
407 const char *providerid, const char *type, uid_t uid,
408 GList **privileges) {
409 char *query = nullptr;
410 query = sqlite3_mprintf(
411 "SELECT privilege FROM package_app_data_control_privilege "
412 "WHERE providerid=%Q AND type=%Q", providerid, type);
413 if (query == nullptr) {
414 LOGE("Out of memory");
415 return PMINFO_R_ERROR;
418 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
419 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
420 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
421 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
423 pkgmgr_client::PkgInfoClient client(parcelable, uid,
424 pkgmgr_common::ReqType::QUERY);
425 if (!client.SendRequest()) {
427 return PMINFO_R_ERROR;
429 // TODO: deliver rawdata to reqhandler directly if server is not working
431 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
432 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
433 client.GetResultParcel()));
435 if (return_parcel == nullptr) {
436 LOG(ERROR) << "Fail to get return parcelable";
437 return PMINFO_R_ERROR;
440 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
441 LOG(ERROR) << "Request fail";
442 return return_parcel->GetRequestResult();
445 tizen_base::Parcel parcel;
446 parcel.ReadParcelable(return_parcel.get());
448 // result_list is vector of string vector
449 auto result_list = return_parcel->GetResult();
450 if (result_list.size() == 0)
451 return PMINFO_R_ENOENT;
453 for (auto result : result_list) {
454 if (result.size() != 1)
455 return PMINFO_R_ERROR;
456 if (result.front().empty() || result.front().size() == 0)
457 return PMINFO_R_ERROR;
458 char *privilege = strdup(result.front().c_str());
459 if (privilege == nullptr) {
460 LOG(ERROR) << "Out of memory";
461 return PMINFO_R_ERROR;
463 *privileges = g_list_append(*privileges, privilege);
469 extern "C" EXPORT_API int _appinfo_get_appcontrol_privileges(
470 const char *appid, const char *operation, uid_t uid, GList **privileges) {
471 char *query = nullptr;
472 query = sqlite3_mprintf(
473 "SELECT app_control, privilege FROM package_app_app_control_privilege "
474 "WHERE app_id=%Q", appid);
475 if (query == nullptr) {
476 LOG(ERROR) << "Out of memory";
477 return PMINFO_R_ERROR;
480 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
481 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
482 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
483 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
485 pkgmgr_client::PkgInfoClient client(parcelable, uid,
486 pkgmgr_common::ReqType::QUERY);
487 if (!client.SendRequest()) {
489 return PMINFO_R_ERROR;
491 // TODO: deliver rawdata to reqhandler directly if server is not working
493 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
494 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
495 client.GetResultParcel()));
497 if (return_parcel == nullptr) {
498 LOG(ERROR) << "Fail to get return parcelable";
499 return PMINFO_R_ERROR;
502 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
503 LOG(ERROR) << "Request fail";
504 return return_parcel->GetRequestResult();
507 tizen_base::Parcel parcel;
508 parcel.ReadParcelable(return_parcel.get());
510 // result_list is vector of string vector
511 auto result_list = return_parcel->GetResult();
512 if (result_list.size() == 0)
513 return PMINFO_R_ENOENT;
515 for (auto result : result_list) {
516 if (result.size() != 2)
517 return PMINFO_R_ERROR;
518 if (result.front().empty() || result.front().size() == 0 ||
519 result.back().empty() || result.back().size() == 0)
520 return PMINFO_R_ERROR;
521 std::string app_control = result.front();
522 std::stringstream ss(app_control);
524 while (std::getline(ss, token, '|')) {
525 if (token.compare(std::string(operation))) {
526 char *privilege = strdup(result.back().c_str());
527 if (privilege == nullptr) {
528 LOG(ERROR) << "Out of memory";
529 return PMINFO_R_ERROR;
531 *privileges = g_list_append(*privileges, privilege);
538 extern "C" EXPORT_API int _plugininfo_get_appids(
539 const char *pkgid, const char *plugin_type,
540 const char *plugin_name, GList **list) {
541 if (!pkgid || !plugin_type || !plugin_name || !list) {
542 LOG(ERROR) << "Invalid parameter";
543 return PMINFO_R_EINVAL;
546 char *query = nullptr;
547 query = sqlite3_mprintf(
549 "package_plugin_info WHERE pkgid=%Q AND "
550 "plugin_type=%Q AND plugin_name=%Q",
551 pkgid, plugin_type, plugin_name);
552 if (query == nullptr) {
553 LOG(ERROR) << "Out of memory";
554 return PMINFO_R_ERROR;
557 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
558 new pkgmgr_common::parcel::QueryParcelable(_getuid(), std::string(query),
559 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
560 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
563 pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
564 pkgmgr_common::ReqType::QUERY);
565 if (!client.SendRequest()) {
566 return PMINFO_R_ERROR;
569 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
570 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
571 client.GetResultParcel()));
573 if (return_parcel == nullptr) {
574 LOG(ERROR) << "Fail to get return parcelable";
575 return PMINFO_R_ERROR;
578 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
579 LOG(ERROR) << "Request fail";
580 return return_parcel->GetRequestResult();
583 if (return_parcel->GetCol() != 1) {
584 LOG(ERROR) << "Invalid result";
585 return PMINFO_R_ERROR;
587 // result_list is vector of string vector
588 auto& result_list = return_parcel->GetResult();
589 if (result_list.size() == 0)
590 return PMINFO_R_ENOENT;
592 for (auto result : result_list) {
593 if (result.size() != 1) {
594 LOG(ERROR) << "Invalid result";
595 g_list_free_full(*list, free);
596 return PMINFO_R_ERROR;
598 *list = g_list_append(*list, strdup(result[0].c_str()));
604 static int __convert_update_type(const char *type, pkgmgrinfo_updateinfo_update_type *convert_type)
606 if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
607 strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
608 *convert_type = PMINFO_UPDATEINFO_NONE;
609 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
610 strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
611 *convert_type = PMINFO_UPDATEINFO_FORCE;
612 else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
613 strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
614 *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
620 static void __free_update_info(gpointer data)
622 updateinfo_x *update_info = (updateinfo_x *)data;
623 if (update_info == nullptr)
626 if (update_info->pkgid)
627 free((void *)update_info->pkgid);
628 if (update_info->version)
629 free((void *)update_info->version);
630 free((void *)update_info);
634 extern "C" EXPORT_API int _get_pkg_updateinfo(const char *pkgid,
635 GSList **update_info_list, uid_t uid)
637 char *query = nullptr;
640 if (pkgid == nullptr)
641 query = sqlite3_mprintf(
642 "SELECT package, update_version, update_type "
643 "FROM package_update_info");
645 query = sqlite3_mprintf(
646 "SELECT package, update_version, update_type "
647 "FROM package_update_info WHERE package=%Q",
649 if (query == nullptr) {
650 LOG(ERROR) << "Out of memory";
651 return PMINFO_R_ERROR;
654 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
655 new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query),
656 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
657 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
660 pkgmgr_client::PkgInfoClient client(parcelable, uid,
661 pkgmgr_common::ReqType::QUERY);
662 if (!client.SendRequest()) {
663 return PMINFO_R_ERROR;
666 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
667 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
668 client.GetResultParcel()));
670 if (return_parcel == nullptr) {
671 LOG(ERROR) << "Fail to get return parcelable";
672 return PMINFO_R_ERROR;
675 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
676 LOG(ERROR) << "Request fail";
677 return return_parcel->GetRequestResult();
680 if (return_parcel->GetCol() != 3) {
681 LOG(ERROR) << "Invalid result";
682 return PMINFO_R_ERROR;
685 auto result_list = return_parcel->GetResult();
686 if (result_list.size() == 0)
687 return PMINFO_R_ENOENT;
689 for (auto result : result_list) {
690 if (result.size() != 3) {
691 LOG(ERROR) << "Invalid result";
692 g_slist_free_full(*update_info_list, __free_update_info);
693 return PMINFO_R_ERROR;
695 updateinfo_x *update_info = reinterpret_cast<updateinfo_x *>(calloc(1, sizeof(updateinfo_x)));
696 if (update_info == nullptr) {
697 LOG(ERROR) << "Out of memory";
698 return PMINFO_R_ERROR;
700 update_info->pkgid = strdup(result[0].c_str());
701 update_info->version = strdup(result[1].c_str());
702 pkgmgrinfo_updateinfo_update_type convert_type;
703 ret = __convert_update_type(result[2].c_str(), &convert_type);
705 __free_update_info(update_info);
706 g_slist_free_full(*update_info_list, __free_update_info);
707 return PMINFO_R_ERROR;
709 update_info->type = static_cast<int>(convert_type);
710 *update_info_list = g_slist_prepend(*update_info_list,
717 extern "C" EXPORT_API int _pkginfo_set_usr_installed_storage(const char *pkgid,
718 INSTALL_LOCATION location, const char *external_pkg_path,
721 char *query = nullptr;
722 const char *location_str;
723 std::vector<std::string> queries;
725 if (location == INSTALL_INTERNAL)
726 location_str = "installed_internal";
727 else if (location == INSTALL_EXTERNAL)
728 location_str = "installed_external";
730 location_str = "installed_extended";
731 /* pkgcakge_info table */
732 query = sqlite3_mprintf(
733 "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
734 location_str, external_pkg_path, pkgid);
735 queries.emplace_back(query);
738 /* package_app_info table */
739 query = sqlite3_mprintf(
740 "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
741 location_str, external_pkg_path, pkgid);
742 queries.emplace_back(query);
745 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
746 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
747 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
748 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
750 pkgmgr_client::PkgInfoClient client(parcelable, uid,
751 pkgmgr_common::ReqType::QUERY);
752 if (!client.SendRequest()) {
753 return PMINFO_R_ERROR;
756 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
757 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
758 client.GetResultParcel()));
760 if (return_parcel == nullptr) {
761 LOG(ERROR) << "Fail to get return parcelable";
762 return PMINFO_R_ERROR;
765 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
766 LOG(ERROR) << "Request fail";
767 return return_parcel->GetRequestResult();
770 auto result_list = return_parcel->GetResult();
771 if (result_list.size() != 1) {
772 LOG(ERROR) << "Invalid result";
773 return PMINFO_R_ERROR;
776 if (result_list[0].size() != 1) {
777 LOG(ERROR) << "Invalid result";
778 return PMINFO_R_ERROR;
781 LOG(ERROR) << "result : " << result_list[0][0];
782 if (result_list[0][0] != "SUCCESS")
783 return PMINFO_R_ERROR;
788 extern "C" EXPORT_API int _certinfo_compare_pkg_certinfo(const char *l_pkgid,
789 const char *r_pkgid, pkgmgrinfo_cert_compare_result_type_e *result) {
790 char *query = sqlite3_mprintf("SELECT package, "
791 "COALESCE(author_signer_cert, -1) FROM package_cert_info WHERE "
792 "package IN (%Q, %Q)", l_pkgid, r_pkgid);
793 if (query == nullptr) {
794 LOG(ERROR) << "Out of memory";
795 return PMINFO_R_ERROR;
797 std::vector<std::string> queries;
798 queries.emplace_back(query);
801 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
802 new pkgmgr_common::parcel::QueryParcelable(0, queries,
803 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
804 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
805 pkgmgr_client::PkgInfoClient client(parcelable, 0,
806 pkgmgr_common::ReqType::QUERY);
807 if (!client.SendRequest()) {
808 return PMINFO_R_ERROR;
811 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
812 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
813 client.GetResultParcel()));
815 if (return_parcel == nullptr) {
816 LOG(ERROR) << "Fail to get return parcelable";
817 return PMINFO_R_ERROR;
820 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
821 LOG(ERROR) << "Request fail";
822 return return_parcel->GetRequestResult();
825 auto certinfo_list = return_parcel->GetResult();
826 if (certinfo_list.size() != 2)
827 return PMINFO_R_ERROR;
829 std::map<std::string, std::string> result_map;
830 for (auto& certinfo : certinfo_list)
831 result_map.insert(make_pair(certinfo.front(), certinfo.back()));
833 if (result_map.find(std::string(l_pkgid))->second == "-1" &&
834 result_map.find(std::string(r_pkgid))->second == "-1")
835 *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
836 else if (result_map.find(std::string(l_pkgid))->second == "-1")
837 *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
838 else if (result_map.find(std::string(r_pkgid))->second == "-1")
839 *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
840 else if (result_map.find(std::string(l_pkgid))->second ==
841 result_map.find(std::string(r_pkgid))->second)
842 *result = PMINFO_CERT_COMPARE_MATCH;
844 *result = PMINFO_CERT_COMPARE_MISMATCH;
849 extern "C" EXPORT_API int _certinfo_compare_app_certinfo(uid_t uid,
850 const char *l_appid, const char *r_appid,
851 pkgmgrinfo_cert_compare_result_type_e *result) {
852 char* query = sqlite3_mprintf("SELECT app_id, package FROM "
853 "package_app_info WHERE app_id IN (%Q, %Q)", l_appid, r_appid);
854 if (query == nullptr) {
855 LOG(ERROR) << "Out of memory";
856 return PMINFO_R_ERROR;
858 std::vector<std::string> queries;
859 queries.emplace_back(query);
862 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
863 new pkgmgr_common::parcel::QueryParcelable(uid, queries,
864 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
865 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_READ));
866 pkgmgr_client::PkgInfoClient client(parcelable, uid,
867 pkgmgr_common::ReqType::QUERY);
868 if (!client.SendRequest()) {
869 return PMINFO_R_ERROR;
872 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
873 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
874 client.GetResultParcel()));
876 if (return_parcel == nullptr) {
877 LOG(ERROR) << "Fail to get return parcelable";
878 return PMINFO_R_ERROR;
881 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
882 LOG(ERROR) << "Request fail";
883 return return_parcel->GetRequestResult();
886 auto pkgid_list = return_parcel->GetResult();
887 std::map<std::string, std::string> result_map;
888 for (auto& pkgid : pkgid_list)
889 result_map.insert(make_pair(pkgid.front(), pkgid.back()));
891 if (result_map.find(std::string(l_appid)) == result_map.end()) {
892 LOG(ERROR) << "Cannot find pkgid of app " << l_appid
893 << " for uid " << uid;
894 return PMINFO_R_ENOENT;
895 } else if (result_map.find(std::string(r_appid)) == result_map.end()) {
896 LOG(ERROR) << "Cannot find pkgid of app " << r_appid
897 << " for uid " << uid;
898 return PMINFO_R_ENOENT;
901 const char* l_pkgid = result_map.find(
902 std::string(l_appid))->second.c_str();
903 const char* r_pkgid = result_map.find(
904 std::string(r_appid))->second.c_str();
906 return _certinfo_compare_pkg_certinfo(l_pkgid, r_pkgid, result);
909 extern "C" EXPORT_API int _parser_execute_write_query(const char *query, uid_t uid)
911 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
912 new pkgmgr_common::parcel::QueryParcelable(uid, query,
913 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
914 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
916 pkgmgr_client::PkgInfoClient client(parcelable, uid,
917 pkgmgr_common::ReqType::QUERY);
918 if (!client.SendRequest()) {
922 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
923 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
924 client.GetResultParcel()));
926 if (return_parcel == nullptr) {
927 LOG(ERROR) << "Fail to get return parcelable";
931 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
932 LOG(ERROR) << "Request fail";
936 auto result_list = return_parcel->GetResult();
937 if (result_list.size() != 1) {
938 LOG(ERROR) << "Invalid result";
942 if (result_list[0].size() != 1) {
943 LOG(ERROR) << "Invalid result";
947 LOG(ERROR) << "result : " << result_list[0][0];
948 if (result_list[0][0] != "SUCCESS")
954 extern "C" EXPORT_API int _parser_execute_write_queries(const char **queries, int len, uid_t uid)
956 std::vector<std::string> query_vt;
957 for (int i = 0; i < len; ++i)
958 query_vt.emplace_back(queries[i]);
960 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
961 new pkgmgr_common::parcel::QueryParcelable(uid, query_vt,
962 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_PKGDB,
963 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
965 pkgmgr_client::PkgInfoClient client(parcelable, uid,
966 pkgmgr_common::ReqType::QUERY);
967 if (!client.SendRequest()) {
971 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
972 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
973 client.GetResultParcel()));
975 if (return_parcel == nullptr) {
976 LOG(ERROR) << "Fail to get return parcelable";
980 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
981 LOG(ERROR) << "Request fail";
985 auto result_list = return_parcel->GetResult();
986 if (result_list.size() != 1) {
987 LOG(ERROR) << "Invalid result";
991 if (result_list[0].size() != 1) {
992 LOG(ERROR) << "Invalid result";
996 LOG(ERROR) << "result : " << result_list[0][0];
997 if (result_list[0][0] != "SUCCESS")
1003 extern "C" EXPORT_API int _parser_insert_manifest_info(manifest_x *mfx, uid_t uid)
1005 std::vector<package_x *> vt { mfx };
1007 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1008 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Insert));
1010 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1011 pkgmgr_common::ReqType::SET_PKG_INFO);
1012 if (!client.SendRequest()) {
1016 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1017 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1018 client.GetResultParcel()));
1020 if (return_parcel == nullptr) {
1021 LOG(ERROR) << "Fail to get return parcelable";
1025 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1026 LOG(ERROR) << "Request fail";
1033 extern "C" EXPORT_API int _parser_update_manifest_info(manifest_x *mfx, uid_t uid)
1035 std::vector<package_x *> vt { mfx };
1037 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1038 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Update));
1040 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1041 pkgmgr_common::ReqType::SET_PKG_INFO);
1042 if (!client.SendRequest()) {
1046 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1047 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1048 client.GetResultParcel()));
1050 if (return_parcel == nullptr) {
1051 LOG(ERROR) << "Fail to get return parcelable";
1055 if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1056 LOG(ERROR) << "Request fail";
1063 extern "C" EXPORT_API int _parser_delete_manifest_info(manifest_x *mfx, uid_t uid)
1065 std::vector<package_x *> vt { mfx };
1067 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1068 new pkgmgr_common::parcel::PkgInfoParcelable(uid, std::move(vt), WriteType::Delete));
1070 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1071 pkgmgr_common::ReqType::SET_PKG_INFO);
1072 if (!client.SendRequest()) {
1076 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1077 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1078 client.GetResultParcel()));
1080 if (return_parcel == nullptr) {
1081 LOG(ERROR) << "Fail to get return parcelable";
1085 if (return_parcel->GetRequestResult() != PM_PARSER_R_OK) {
1086 LOG(ERROR) << "Request fail";
1093 extern "C" EXPORT_API int _pkginfo_insert_certinfo(const char* pkgid,
1094 pkgmgr_certinfo_x* cert, uid_t uid)
1096 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1097 new pkgmgr_common::parcel::CertInfoParcelable(uid, cert));
1099 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1100 pkgmgr_common::ReqType::SET_CERT_INFO);
1101 if (!client.SendRequest())
1102 return PMINFO_R_ERROR;
1104 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1105 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1106 client.GetResultParcel()));
1108 if (return_parcel == nullptr) {
1109 LOG(ERROR) << "Fail to get return parcelable";
1110 return PMINFO_R_ERROR;
1113 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1114 LOG(ERROR) << "Request fail";
1115 return return_parcel->GetRequestResult();
1121 extern "C" EXPORT_API int _pkginfo_get_certinfo(const char *pkgid,
1122 pkgmgr_certinfo_x** cert, uid_t uid)
1124 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1125 new pkgmgr_common::parcel::CertInfoParcelable(uid,
1126 std::string(pkgid)));
1128 pkgmgr_client::PkgInfoClient client(parcelable, uid,
1129 pkgmgr_common::ReqType::GET_CERT_INFO);
1130 if (!client.SendRequest())
1131 return PMINFO_R_ERROR;
1133 std::shared_ptr<pkgmgr_common::parcel::CertInfoParcelable> return_parcel(
1134 std::static_pointer_cast<pkgmgr_common::parcel::CertInfoParcelable>(
1135 client.GetResultParcel()));
1137 if (return_parcel == nullptr) {
1138 LOG(ERROR) << "Fail to get return parcelable";
1139 return PMINFO_R_ERROR;
1142 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1143 LOG(ERROR) << "Request fail";
1144 return return_parcel->GetRequestResult();
1147 tizen_base::Parcel parcel;
1148 parcel.ReadParcelable(return_parcel.get());
1149 auto certinfo = return_parcel->GetCertInfo();
1150 if (certinfo == nullptr)
1151 return PMINFO_R_ERROR;
1153 *cert = (pkgmgr_certinfo_x*)certinfo;
1157 extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char *pkgid)
1159 char* query = sqlite3_mprintf("UPDATE package_cert_info SET "
1160 "package_count = package_count - 1 WHERE package=%Q", pkgid);
1161 if (query == nullptr) {
1162 LOG(ERROR) << "Out of memory";
1163 return PMINFO_R_ERROR;
1166 std::vector<std::string> queries;
1167 queries.emplace_back(query);
1168 sqlite3_free(query);
1170 std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
1171 new pkgmgr_common::parcel::QueryParcelable(0, queries,
1172 pkgmgr_common::database::AbstractDBHandler::DBType::DB_TYPE_FILE_CERTDB,
1173 pkgmgr_common::database::AbstractDBHandler::OperationType::OPERATION_TYPE_WRITE));
1175 pkgmgr_client::PkgInfoClient client(parcelable, 0,
1176 pkgmgr_common::ReqType::QUERY);
1177 if (!client.SendRequest()) {
1178 return PMINFO_R_ERROR;
1181 std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
1182 std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
1183 client.GetResultParcel()));
1185 if (return_parcel == nullptr) {
1186 LOG(ERROR) << "Fail to get return parcelable";
1187 return PMINFO_R_ERROR;
1190 if (return_parcel->GetRequestResult() != PMINFO_R_OK) {
1191 LOG(ERROR) << "Request fail";
1192 return return_parcel->GetRequestResult();
1195 auto result_list = return_parcel->GetResult();
1196 if (result_list.size() != 1) {
1197 LOG(ERROR) << "Invalid result";
1198 return PMINFO_R_ERROR;
1201 if (result_list[0].size() != 1) {
1202 LOG(ERROR) << "Invalid result";
1203 return PMINFO_R_ERROR;
1206 LOG(ERROR) << "result : " << result_list[0][0];
1207 if (result_list[0][0] != "SUCCESS")
1208 return PMINFO_R_ERROR;