2 * Copyright (c) 2022 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.
19 #include <tzplatform_config.h>
21 #include "include/package-manager-types.h"
22 #include "include/package-manager-plugin.h"
24 #include "client/include/package-manager.h"
25 #include "client/src/connector.hh"
26 #include "client/src/log.hh"
27 #include "client/src/internal.hh"
32 #define API __attribute__ ((visibility("default")))
34 #define CONNECTION_RETRY_MAX 5
35 #define CONNECTION_WAIT_USEC (1000000 / 2) /* 0.5 sec */
36 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
37 #define REGULAR_USER 5000
39 using pkgmgr::client::Connector;
43 static int GetDelayedResult(pkgmgr_client *pc, const std::string& req_key) {
45 _E("invalid parameter");
46 return PKGMGR_R_EINVAL;
49 auto* con = static_cast<Connector*>(pc);
50 if (con->GetPcType() != PC_REQUEST) {
51 _E("client type is not PC_REQUEST");
52 return PKGMGR_R_EINVAL;
55 auto* proxy = con->GetDelayedResultProxy();
62 if (proxy->GetResult(req_key, ret) == PKGMGR_R_OK)
65 _E("Failed to get result sleep and retry[%d/%d]",
66 retry_cnt, CONNECTION_RETRY_MAX);
67 usleep(CONNECTION_WAIT_USEC);
69 } while (retry_cnt <= CONNECTION_RETRY_MAX);
71 _E("Failed to get result");
72 return PKGMGR_R_ERROR;
75 static int ResultGetSizeSync(pkgmgr_client *pc, const std::string& req_key) {
77 _E("invalid parameter");
78 return PKGMGR_R_EINVAL;
81 auto* con = static_cast<Connector*>(pc);
82 if (con->GetPcType() != PC_REQUEST) {
83 _E("client type is not PC_REQUEST");
84 return PKGMGR_R_EINVAL;
87 auto* proxy = con->GetInfoProxy();
92 int ret = PKGMGR_R_ECOMM;
93 long long size_info = 0;
95 if (proxy->GetSizeSyncResult(req_key, ret, size_info) == PKGMGR_R_OK) {
96 if (ret != PKGMGR_R_OK) {
97 _E("request result failed: %d", ret);
102 _E("invalid size_info=(%lld)", size_info);
106 _D("size_info(%lld), return size(%d)", size_info, ret);
110 _E("Failed to get result sleep and retry[%d/%d]",
111 retry_cnt, CONNECTION_RETRY_MAX);
112 usleep(CONNECTION_WAIT_USEC);
114 } while (retry_cnt <= CONNECTION_RETRY_MAX);
116 _E("Failed to get result");
120 static int GetGenerateLicenseResult(pkgmgr_client *pc,
121 const std::string& req_key, std::string &reqData, std::string &licenseUrl) {
123 _E("invalid parameter");
124 return PKGMGR_R_EINVAL;
127 auto* con = static_cast<Connector*>(pc);
128 if (con->GetPcType() != PC_REQUEST) {
129 _E("client type is not PC_REQUEST");
130 return PKGMGR_R_EINVAL;
133 auto* proxy = con->GetAdminProxy();
134 if (proxy == nullptr)
138 int ret = PKGMGR_R_ECOMM;
140 if (proxy->GetGenerateLicenseResult(req_key,
141 ret, reqData, licenseUrl) == PKGMGR_R_OK)
144 _E("Failed to get result sleep and retry[%d/%d]",
145 retry_cnt, CONNECTION_RETRY_MAX);
146 usleep(CONNECTION_WAIT_USEC);
148 } while (retry_cnt <= CONNECTION_RETRY_MAX);
150 _E("Failed to get result");
154 static inline uid_t GetUid() {
155 uid_t uid = getuid();
157 if (uid < REGULAR_USER)
165 API pkgmgr_client* pkgmgr_client_new(pkgmgr_client_type pc_type) {
166 if (pc_type != PC_REQUEST && pc_type != PC_LISTENING) {
167 _E("invalid parameter(%d)", pc_type);
171 return new Connector(pc_type);
174 API int pkgmgr_client_free(pkgmgr_client* pc) {
176 _E("invalid argument");
177 return PKGMGR_R_EINVAL;
180 Connector* con = static_cast<Connector*>(pc);
186 API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, const char *tep_path,
188 if (pc == nullptr || tep_path == nullptr) {
189 _E("invalied parameter");
190 return PKGMGR_R_EINVAL;
193 Connector* con = static_cast<Connector*>(pc);
194 con->SetTep(tep_path, tep_move);
198 API int pkgmgr_client_usr_install_packages(pkgmgr_client *pc,
199 const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb,
200 void *data, uid_t uid) {
201 if (pc == nullptr || pkg_paths == nullptr || n_pkgs < 1) {
202 _E("invalid parameter");
203 return PKGMGR_R_EINVAL;
206 auto* con = static_cast<Connector*>(pc);
207 if (con->GetPcType() != PC_REQUEST) {
208 _E("client type is not PC_REQUEST");
209 return PKGMGR_R_EINVAL;
212 auto* proxy = con->GetAdminProxy();
213 if (proxy == nullptr)
217 std::vector<std::string> pkgs;
218 for (int i = 0; i < n_pkgs; i++)
219 pkgs.push_back(pkg_paths[i]);
221 const auto& receiver = con->GetSignalReceiver();
222 int ret = proxy->InstallPkgs(uid, pkgs, con->GetArgv(),
223 con->GenerateRequestId(), req_key);
224 if (ret != PKGMGR_R_OK)
227 return receiver->AddEventHandler(req_key, event_cb, data);
230 API int pkgmgr_client_install_packages(pkgmgr_client *pc,
231 const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb,
233 return pkgmgr_client_usr_install_packages(pc, pkg_paths, n_pkgs,
234 event_cb, data, getuid());
237 API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type,
238 const char *descriptor_path, const char *pkg_path,
239 const char *optional_data, pkgmgr_mode mode,
240 pkgmgr_handler event_cb, void *data) {
241 return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path, pkg_path,
242 optional_data, mode, event_cb, data, getuid());
245 API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
246 const char *descriptor_path, const char *pkg_path,
247 const char *optional_data, pkgmgr_mode mode,
248 pkgmgr_handler event_cb, void *data, uid_t uid) {
249 if (pc == nullptr || pkg_path == nullptr) {
250 _E("invalid parameter");
251 return PKGMGR_R_EINVAL;
254 auto* con = static_cast<Connector*>(pc);
255 if (con->GetPcType() != PC_REQUEST) {
256 _E("client type is not PC_REQUEST");
257 return PKGMGR_R_EINVAL;
260 if (access(pkg_path, F_OK) != 0) {
261 _E("failed to access: %s", pkg_path);
262 return PKGMGR_R_EINVAL;
265 if (!con->GetTepPath().empty()) {
266 if (access(con->GetTepPath().c_str(), F_OK) != 0) {
267 _E("failed to access: %s", con->GetTepPath().c_str());
268 return PKGMGR_R_EINVAL;
274 auto* proxy = con->GetAdminProxy();
275 if (proxy == nullptr)
278 const auto& receiver = con->GetSignalReceiver();
280 int ret = proxy->Install(uid, pkg_type ? pkg_type : "", pkg_path, con->GetArgv(),
281 con->GenerateRequestId(), req_key);
282 if (ret != PKGMGR_R_OK)
285 return receiver->AddEventHandler(req_key, event_cb, data);
288 API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type,
289 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
290 pkgmgr_handler event_cb, void *data) {
291 return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data,
292 mode, event_cb, data, getuid());
295 API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type,
296 const char *pkgid, const char *optional_data, pkgmgr_mode mode,
297 pkgmgr_handler event_cb, void *data, uid_t uid) {
298 if (pc == nullptr || pkgid == nullptr) {
299 _E("invalid parameter");
300 return PKGMGR_R_EINVAL;
303 auto* con = static_cast<Connector*>(pc);
304 if (con->GetPcType() != PC_REQUEST) {
305 _E("client type is not PC_REQUEST");
306 return PKGMGR_R_EINVAL;
309 auto* proxy = con->GetAdminProxy();
310 if (proxy == nullptr)
313 const auto& receiver = con->GetSignalReceiver();
315 int ret = proxy->Reinstall(uid, pkgid, req_key);
316 if (ret != PKGMGR_R_OK)
319 return receiver->AddEventHandler(req_key, event_cb, data);
322 API int pkgmgr_client_uninstall_packages(pkgmgr_client *pc,
323 const char **pkgids, int n_pkgs, pkgmgr_handler event_cb,
325 return pkgmgr_client_usr_uninstall_packages(pc, pkgids, n_pkgs,
326 event_cb, data, getuid());
329 API int pkgmgr_client_usr_uninstall_packages(pkgmgr_client *pc,
330 const char **pkgids, int n_pkgs, pkgmgr_handler event_cb,
331 void *data, uid_t uid) {
332 if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) {
333 _E("invalid parameter");
334 return PKGMGR_R_EINVAL;
337 auto* con = static_cast<Connector*>(pc);
338 if (con->GetPcType() != PC_REQUEST) {
339 _E("client type is not PC_REQUEST");
340 return PKGMGR_R_EINVAL;
343 auto* proxy = con->GetAdminProxy();
344 if (proxy == nullptr)
348 std::vector<std::string> pkgs;
349 for (int i = 0; i < n_pkgs; i++)
350 pkgs.push_back(pkgids[i]);
352 const auto& receiver = con->GetSignalReceiver();
353 int ret = proxy->UninstallPkgs(uid, pkgs, req_key);
354 if (ret != PKGMGR_R_OK)
357 return receiver->AddEventHandler(req_key, event_cb, data);
360 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
361 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
363 return pkgmgr_client_usr_uninstall(pc, pkg_type, pkgid, mode, event_cb,
367 API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
368 const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb,
369 void *data, uid_t uid) {
370 if (pc == nullptr || pkgid == nullptr) {
371 _E("invalid parameter");
372 return PKGMGR_R_EINVAL;
375 auto* con = static_cast<Connector*>(pc);
376 if (con->GetPcType() != PC_REQUEST) {
377 _E("client type is not PC_REQUEST");
378 return PKGMGR_R_EINVAL;
381 auto* proxy = con->GetAdminProxy();
382 if (proxy == nullptr)
385 const auto& receiver = con->GetSignalReceiver();
387 int ret = proxy->Uninstall(uid, pkgid, req_key);
388 if (ret != PKGMGR_R_OK)
391 return receiver->AddEventHandler(req_key, event_cb, data);
394 API int pkgmgr_client_listen_res_status(pkgmgr_client *pc,
395 pkgmgr_res_handler event_cb, void *data) {
396 Connector* con = static_cast<Connector*>(pc);
397 if (con->GetPcType() != PC_LISTENING) {
398 _E("client->pc_type is not PC_LISTENING");
399 return PKGMGR_R_EINVAL;
403 const auto& receiver = con->GetSignalReceiver();
404 return receiver->AddEventHandler("", event_cb, data);
406 _E("exception occured");
407 return PKGMGR_R_ERROR;
411 API int pkgmgr_client_listen_pkg_upgrade_status(pkgmgr_client *pc,
412 pkgmgr_pkg_upgrade_handler event_cb, void *data) {
417 API int pkgmgr_client_usr_mount_install_packages(pkgmgr_client *pc,
418 const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb,
419 void *data, uid_t uid) {
420 if (pc == nullptr || pkg_paths == nullptr || n_pkgs < 1) {
421 _E("invalid parameter");
422 return PKGMGR_R_EINVAL;
425 auto* con = static_cast<Connector*>(pc);
426 if (con->GetPcType() != PC_REQUEST) {
427 _E("client type is not PC_REQUEST");
428 return PKGMGR_R_EINVAL;
431 auto* proxy = con->GetAdminProxy();
432 if (proxy == nullptr)
436 std::vector<std::string> pkgs;
437 for (int i = 0; i < n_pkgs; i++) {
438 if (access(pkg_paths[i], F_OK) != 0) {
439 _E("failed to access: %s", pkg_paths[i]);
440 return PKGMGR_R_EINVAL;
443 pkgs.push_back(pkg_paths[i]);
446 const auto& receiver = con->GetSignalReceiver();
447 int ret = proxy->MountInstallPkgs(uid, pkgs, con->GenerateRequestId(),
449 if (ret != PKGMGR_R_OK)
452 return receiver->AddEventHandler(req_key, event_cb, data);
455 API int pkgmgr_client_mount_install_packages(pkgmgr_client *pc,
456 const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb,
458 return pkgmgr_client_usr_mount_install_packages(pc, pkg_paths, n_pkgs,
459 event_cb, data, getuid());
462 API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type,
463 const char *descriptor_path, const char *pkg_path,
464 const char *optional_data, pkgmgr_mode mode,
465 pkgmgr_handler event_cb, void *data) {
466 return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path,
467 pkg_path, optional_data, mode, event_cb, data,
471 API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type,
472 const char *descriptor_path, const char *pkg_path,
473 const char *optional_data, pkgmgr_mode mode,
474 pkgmgr_handler event_cb, void *data, uid_t uid) {
475 if (pc == nullptr || pkg_path == nullptr) {
476 _E("invalid parameter");
477 return PKGMGR_R_EINVAL;
480 auto* con = static_cast<Connector*>(pc);
481 if (con->GetPcType() != PC_REQUEST) {
482 _E("client type is not PC_REQUEST");
483 return PKGMGR_R_EINVAL;
486 if (access(pkg_path, F_OK) != 0) {
487 _E("failed to access: %s", pkg_path);
488 return PKGMGR_R_EINVAL;
491 if (!con->GetTepPath().empty()) {
492 if (access(con->GetTepPath().c_str(), F_OK) != 0) {
493 _E("failed to access: %s", con->GetTepPath().c_str());
494 return PKGMGR_R_EINVAL;
500 auto* proxy = con->GetAdminProxy();
501 if (proxy == nullptr)
504 const auto& receiver = con->GetSignalReceiver();
506 int ret = proxy->MountInstall(uid, pkg_type ? pkg_type : "", pkg_path,
507 con->GetArgv(), con->GenerateRequestId(), req_key);
508 if (ret != PKGMGR_R_OK)
511 return receiver->AddEventHandler(req_key, event_cb, data);
514 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
515 const char *pkgid, pkgmgr_move_type move_type,
516 pkgmgr_handler event_cb, void *data) {
517 return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type,
518 event_cb, data, getuid());
521 API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
522 const char *pkgid, pkgmgr_move_type move_type,
523 pkgmgr_handler event_cb, void *data, uid_t uid) {
524 if (pc == nullptr || pkgid == nullptr) {
525 _E("invalid parameter");
526 return PKGMGR_R_EINVAL;
529 if ((move_type < PM_MOVE_TO_INTERNAL) ||
530 (move_type > PM_MOVE_TO_EXTENDED))
531 return PKGMGR_R_EINVAL;
533 auto* con = static_cast<Connector*>(pc);
534 if (con->GetPcType() != PC_REQUEST) {
535 _E("client type is not PC_REQUEST");
536 return PKGMGR_R_EINVAL;
539 auto* proxy = con->GetAdminProxy();
540 if (proxy == nullptr)
543 const auto& receiver = con->GetSignalReceiver();
545 int ret = proxy->Move(uid, pkgid, move_type, req_key);
546 if (ret != PKGMGR_R_OK)
549 return receiver->AddEventHandler(req_key, event_cb, data);
552 API int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc,
553 pkg_update_info_t *update_info) {
554 return pkgmgr_client_usr_register_pkg_update_info(pc, update_info,
558 API int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc,
559 pkg_update_info_t *update_info, uid_t uid) {
560 if (pc == nullptr || update_info == nullptr || update_info->pkgid == nullptr) {
561 _E("invalid parameter");
562 return PKGMGR_R_EINVAL;
565 auto* con = static_cast<Connector*>(pc);
566 if (con->GetPcType() != PC_REQUEST) {
567 _E("client type is not PC_REQUEST");
568 return PKGMGR_R_EINVAL;
571 auto* proxy = con->GetAdminProxy();
572 if (proxy == nullptr)
576 int ret = proxy->RegisterPkgUpdateInfo(uid, update_info->pkgid,
577 update_info->pkgid, update_info->type, req_key);
583 return GetDelayedResult(pc, req_key);
586 API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc,
587 const char *pkgid, uid_t uid) {
588 if (pc == nullptr || pkgid == nullptr) {
589 _E("invalid parameter");
590 return PKGMGR_R_EINVAL;
593 auto* con = static_cast<Connector*>(pc);
594 if (con->GetPcType() != PC_REQUEST) {
595 _E("client type is not PC_REQUEST");
596 return PKGMGR_R_EINVAL;
599 auto* proxy = con->GetAdminProxy();
600 if (proxy == nullptr)
604 int ret = proxy->UnregisterPkgUpdateInfo(uid, pkgid, req_key);
611 return GetDelayedResult(pc, req_key);
614 API int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc,
616 return pkgmgr_client_usr_unregister_pkg_update_info(pc, pkgid, getuid());
619 API int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc,
622 _E("invalid parameter");
623 return PKGMGR_R_EINVAL;
626 auto* con = static_cast<Connector*>(pc);
627 if (con->GetPcType() != PC_REQUEST) {
628 _E("client type is not PC_REQUEST");
629 return PKGMGR_R_EINVAL;
632 auto* proxy = con->GetAdminProxy();
633 if (proxy == nullptr)
637 return proxy->UnregisterAllPkgUpdateInfo(uid, req_key);
640 API int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc) {
641 return pkgmgr_client_usr_unregister_all_pkg_update_info(pc, getuid());
644 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
645 const char *pkgid, uid_t uid) {
646 if (pc == nullptr || pkgid == nullptr) {
647 _E("invalid parameter");
648 return PKGMGR_R_EINVAL;
651 auto* con = static_cast<Connector*>(pc);
652 auto* proxy = con->GetAdminProxy();
653 if (proxy == nullptr)
657 return proxy->EnablePkgs(uid, { pkgid }, req_key);
660 API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type,
662 return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, getuid());
665 API int pkgmgr_client_usr_activate_packages(pkgmgr_client *pc,
666 const char *pkg_type, const char **pkgids, int n_pkgs,
667 pkgmgr_handler event_cb, void *data, uid_t uid) {
668 if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) {
669 _E("invalid parameter");
670 return PKGMGR_R_EINVAL;
673 auto* con = static_cast<Connector*>(pc);
674 if (con->GetPcType() != PC_REQUEST) {
675 _E("client type is not PC_REQUEST");
676 return PKGMGR_R_EINVAL;
679 auto* proxy = con->GetAdminProxy();
680 if (proxy == nullptr)
684 std::vector<std::string> vec;
685 for (int i = 0; i < n_pkgs; i++) {
686 vec.push_back(pkgids[i]);
689 const auto& receiver = con->GetSignalReceiver();
690 int ret = proxy->EnablePkgs(uid, std::move(vec), req_key);
691 if (ret != PKGMGR_R_OK)
694 return receiver->AddEventHandler(req_key, event_cb, data);
697 API int pkgmgr_client_activate_packages(pkgmgr_client *pc,
698 const char *pkg_type, const char **pkgids, int n_pkgs,
699 pkgmgr_handler event_cb, void *data) {
700 return pkgmgr_client_usr_activate_packages(pc, pkg_type,
701 pkgids, n_pkgs, event_cb, data, getuid());
704 API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
705 const char *pkgid, uid_t uid) {
706 if (pc == nullptr || pkgid == nullptr) {
707 _E("invalid parameter");
708 return PKGMGR_R_EINVAL;
711 auto* con = static_cast<Connector*>(pc);
712 auto* proxy = con->GetAdminProxy();
713 if (proxy == nullptr)
717 return proxy->DisablePkgs(uid, { pkgid }, req_key);
720 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
722 return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, getuid());
725 API int pkgmgr_client_usr_deactivate_packages(pkgmgr_client *pc,
726 const char *pkg_type, const char **pkgids, int n_pkgs,
727 pkgmgr_handler event_cb, void *data, uid_t uid) {
728 if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) {
729 _E("invalid parameter");
730 return PKGMGR_R_EINVAL;
733 auto* con = static_cast<Connector*>(pc);
734 if (con->GetPcType() != PC_REQUEST) {
735 _E("client type is not PC_REQUEST");
736 return PKGMGR_R_EINVAL;
739 auto* proxy = con->GetAdminProxy();
740 if (proxy == nullptr)
744 std::vector<std::string> vec;
745 for (int i = 0; i < n_pkgs; i++) {
746 vec.push_back(pkgids[i]);
748 const auto& receiver = con->GetSignalReceiver();
749 int ret = proxy->DisablePkgs(uid, std::move(vec), req_key);
750 if (ret != PKGMGR_R_OK)
753 return receiver->AddEventHandler(req_key, event_cb, data);
756 API int pkgmgr_client_deactivate_packages(pkgmgr_client *pc,
757 const char *pkg_type, const char **pkgids, int n_pkgs,
758 pkgmgr_handler event_cb, void *data) {
759 return pkgmgr_client_usr_deactivate_packages(pc, pkg_type,
760 pkgids, n_pkgs, event_cb, data, getuid());
763 API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid,
764 pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
765 if (pc == nullptr || appid == nullptr) {
766 _E("invalid parameter");
767 return PKGMGR_R_EINVAL;
770 auto* con = static_cast<Connector*>(pc);
771 auto* proxy = con->GetAdminProxy();
772 if (proxy == nullptr)
775 const auto& receiver = con->GetSignalReceiver();
777 int ret = proxy->EnableApp(uid, appid, req_key);
778 if (ret != PKGMGR_R_OK)
781 return receiver->AddEventHandler(req_key, app_event_cb, data);
784 API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid,
785 pkgmgr_app_handler app_event_cb, void *data) {
786 return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb,
790 API int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids,
791 int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
792 if (pc == nullptr || appids == nullptr || n_apps < 1) {
793 _E("invalid parameter");
794 return PKGMGR_R_EINVAL;
797 auto* con = static_cast<Connector*>(pc);
798 if (con->GetPcType() != PC_REQUEST) {
799 _E("client type is not PC_REQUEST");
800 return PKGMGR_R_EINVAL;
803 auto* proxy = con->GetAdminProxy();
804 if (proxy == nullptr)
808 std::vector<std::string> vec;
809 for (int i = 0; i < n_apps; i++) {
810 vec.push_back(appids[i]);
813 const auto& receiver = con->GetSignalReceiver();
814 int ret = proxy->EnableApps(uid, std::move(vec), req_key);
815 if (ret != PKGMGR_R_OK)
818 return receiver->AddEventHandler(req_key, app_event_cb, data);
821 API int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids,
822 int n_apps, pkgmgr_app_handler app_event_cb, void *data) {
823 return pkgmgr_client_usr_activate_apps(pc, appids, n_apps,
824 app_event_cb, data, getuid());
827 API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc,
828 const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
829 if (pc == nullptr || appid == nullptr) {
830 _E("invalid parameter");
831 return PKGMGR_R_EINVAL;
834 auto* con = static_cast<Connector*>(pc);
835 auto* proxy = con->GetAdminProxy();
836 if (proxy == nullptr)
839 const auto& receiver = con->GetSignalReceiver();
841 int ret = proxy->EnableGlobalAppForUid(uid, appid, req_key);
842 if (ret != PKGMGR_R_OK)
845 return receiver->AddEventHandler(req_key, app_event_cb, data);
848 API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid,
849 pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
850 if (pc == nullptr || appid == nullptr) {
851 _E("invalid parameter");
852 return PKGMGR_R_EINVAL;
855 auto* con = static_cast<Connector*>(pc);
856 auto* proxy = con->GetAdminProxy();
857 if (proxy == nullptr)
860 const auto& receiver = con->GetSignalReceiver();
862 int ret = proxy->DisableApp(uid, appid, req_key);
863 if (ret != PKGMGR_R_OK)
866 return receiver->AddEventHandler(req_key, app_event_cb, data);
869 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid,
870 pkgmgr_app_handler app_event_cb, void *data) {
871 return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, data,
875 API int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc,
876 const char **appids, int n_apps,
877 pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
878 if (pc == nullptr || appids == nullptr || n_apps < 1) {
879 _E("invalid parameter");
880 return PKGMGR_R_EINVAL;
883 auto* con = static_cast<Connector*>(pc);
884 if (con->GetPcType() != PC_REQUEST) {
885 _E("client type is not PC_REQUEST");
886 return PKGMGR_R_EINVAL;
889 auto* proxy = con->GetAdminProxy();
890 if (proxy == nullptr)
894 std::vector<std::string> vec;
895 for (int i = 0; i < n_apps; i++) {
896 vec.push_back(appids[i]);
899 const auto& receiver = con->GetSignalReceiver();
900 int ret = proxy->DisableApps(uid, std::move(vec), req_key);
901 if (ret != PKGMGR_R_OK)
904 return receiver->AddEventHandler(req_key, app_event_cb, data);
907 API int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids,
908 int n_apps, pkgmgr_app_handler app_event_cb, void *data) {
909 return pkgmgr_client_usr_deactivate_apps(pc, appids, n_apps,
910 app_event_cb, data, getuid());
913 API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc,
914 const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) {
915 if (pc == nullptr || appid == nullptr) {
916 _E("invalid parameter");
917 return PKGMGR_R_EINVAL;
920 auto* con = static_cast<Connector*>(pc);
921 auto* proxy = con->GetAdminProxy();
922 if (proxy == nullptr)
925 const auto& receiver = con->GetSignalReceiver();
927 int ret = proxy->DisableGlobalAppForUid(uid, appid, req_key);
928 if (ret != PKGMGR_R_OK)
931 return receiver->AddEventHandler(req_key, app_event_cb, data);
934 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
935 const char *pkgid, pkgmgr_mode mode) {
936 return pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, mode,
940 API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
941 const char *pkg_type, const char *pkgid, pkgmgr_mode mode,
943 if (pc == nullptr || pkgid == nullptr || uid == GLOBAL_USER) {
944 _E("invalid parameter");
945 return PKGMGR_R_EINVAL;
948 auto* con = static_cast<Connector*>(pc);
949 if (con->GetPcType() != PC_REQUEST) {
950 _E("client type is not PC_REQUEST");
951 return PKGMGR_R_EINVAL;
954 auto* proxy = con->GetAdminProxy();
955 if (proxy == nullptr)
958 return proxy->ClearData(uid, pkgid);
961 API int pkgmgr_client_usr_clear_user_data_with_path(pkgmgr_client *pc,
962 const char *pkg_type, const char *pkgid, const char *file_path,
963 pkgmgr_mode mode, uid_t uid)
965 if (!pc || !pkgid || !file_path || uid == GLOBAL_USER) {
966 _E("invalid parameter");
967 return PKGMGR_R_EINVAL;
970 auto* con = static_cast<Connector*>(pc);
971 if (con->GetPcType() != PC_REQUEST) {
972 _E("client type is not PC_REQUEST");
973 return PKGMGR_R_EINVAL;
976 auto* proxy = con->GetAdminProxy();
977 if (proxy == nullptr)
980 return proxy->ClearDataWithPath(uid, pkgid, file_path);
983 API int pkgmgr_client_clear_user_data_with_path(pkgmgr_client *pc, const char *pkg_type,
984 const char *pkgid, const char *file_path, pkgmgr_mode mode)
986 return pkgmgr_client_usr_clear_user_data_with_path(pc, pkg_type, pkgid,
987 file_path, mode, GetUid());
990 API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type) {
995 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
997 if (pc == nullptr || event_cb == nullptr) {
998 _E("invalid parameter");
999 return PKGMGR_R_EINVAL;
1002 auto* con = static_cast<Connector*>(pc);
1003 if (con->GetPcType() != PC_LISTENING) {
1004 _E("client->pc_type is not PC_LISTENING");
1005 return PKGMGR_R_EINVAL;
1009 const auto& receiver = con->GetSignalReceiver();
1010 return receiver->AddEventHandler("", event_cb, data);
1012 _E("exception occured");
1013 return PKGMGR_R_ERROR;
1017 API int pkgmgr_client_listen_app_status(pkgmgr_client *pc,
1018 pkgmgr_app_handler app_event_cb, void *data) {
1019 if (pc == nullptr || app_event_cb == nullptr) {
1020 _E("invalid parameter");
1021 return PKGMGR_R_EINVAL;
1024 auto* con = static_cast<Connector*>(pc);
1025 if (con->GetPcType() != PC_LISTENING) {
1026 _E("client->pc_type is not PC_LISTENING");
1027 return PKGMGR_R_EINVAL;
1031 const auto& receiver = con->GetSignalReceiver();
1032 return receiver->AddEventHandler("", app_event_cb, data);
1034 _E("exception occured");
1035 return PKGMGR_R_ERROR;
1039 API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc) {
1044 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1045 const char *pkgid, const char *key, const char *val) {
1046 /* client cannot broadcast signal */
1050 /* TODO: deprecate(or remove) */
1051 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
1052 int service_mode, pkgmgr_client *pc, const char *pkg_type,
1053 const char *pkgid, const char *custom_info,
1054 pkgmgr_handler event_cb, void *data) {
1055 return pkgmgr_client_usr_request_service(service_type, service_mode,
1056 pc, pkg_type, pkgid, getuid(), custom_info, event_cb,
1060 API int pkgmgr_client_usr_request_service(
1061 pkgmgr_request_service_type service_type, int service_mode,
1062 pkgmgr_client *pc, const char *pkg_type, const char *pkgid,
1063 uid_t uid, const char *custom_info, pkgmgr_handler event_cb,
1065 switch (service_type) {
1066 case PM_REQUEST_MOVE: {
1067 return pkgmgr_client_usr_move(pc, pkg_type, pkgid,
1068 static_cast<pkgmgr_move_type>(service_mode),
1069 event_cb, data, uid);
1071 case PM_REQUEST_GET_SIZE: {
1072 auto* con = static_cast<Connector*>(pc);
1073 auto* proxy = con->GetInfoProxy();
1074 std::string req_key;
1075 int ret = proxy->GetSizeSync(uid, pkgid, service_mode, req_key);
1076 if (ret != PKGMGR_R_OK)
1079 return ResultGetSizeSync(pc, req_key);
1081 case PM_REQUEST_KILL_APP: {
1082 auto* con = static_cast<Connector*>(pc);
1083 auto* proxy = con->GetAdminProxy();
1085 int ret = proxy->Kill(uid, pkgid, pid);
1090 case PM_REQUEST_CHECK_APP: {
1091 auto* con = static_cast<Connector*>(pc);
1092 auto* proxy = con->GetInfoProxy();
1094 int ret = proxy->Check(uid, pkgid, pid);
1100 _E("Wrong Request");
1106 API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) {
1108 _E("invalid parameter");
1109 return PKGMGR_R_EINVAL;
1112 auto* con = new Connector(PC_REQUEST);
1113 auto* proxy = con->GetCacheProxy();
1114 if (proxy == nullptr)
1115 return PKGMGR_R_EIO;
1117 int ret = proxy->ClearCache(uid, pkgid);
1123 API int pkgmgr_client_clear_cache_dir(const char *pkgid) {
1124 return pkgmgr_client_usr_clear_cache_dir(pkgid, getuid());
1127 API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid) {
1128 return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid);
1131 API int pkgmgr_client_clear_all_cache_dir() {
1132 return pkgmgr_client_usr_clear_cache_dir(
1133 PKG_CLEAR_ALL_CACHE, getuid());
1136 API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid,
1137 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1139 return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data,
1143 /* TODO: deprecate(or remove) */
1144 API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid,
1145 pkgmgr_getsize_type get_type, pkgmgr_handler event_cb,
1146 void *data, uid_t uid) {
1147 if (pc == nullptr || pkgid == nullptr || event_cb == nullptr) {
1148 _E("invalid parameter");
1149 return PKGMGR_R_EINVAL;
1152 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1153 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1155 get_type = PM_GET_PKG_SIZE_INFO;
1157 auto* con = static_cast<Connector*>(pc);
1158 if (con->GetPcType() != PC_REQUEST) {
1159 _E("client type is not PC_REQUEST");
1160 return PKGMGR_R_EINVAL;
1163 auto* proxy = con->GetInfoProxy();
1164 if (proxy == nullptr)
1165 return PKGMGR_R_EIO;
1167 const auto& receiver = con->GetSignalReceiver();
1168 std::string req_key;
1169 int ret = proxy->GetSize(uid, pkgid, get_type, req_key);
1170 if (ret != PKGMGR_R_OK)
1173 return receiver->AddEventHandler(req_key, event_cb, data);
1176 API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc,
1177 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1179 return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb,
1180 user_data, getuid());
1183 API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc,
1184 pkgmgr_total_pkg_size_info_receive_cb event_cb,
1185 void *user_data, uid_t uid) {
1186 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL,
1187 (pkgmgr_pkg_size_info_receive_cb)event_cb,
1191 API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc,
1192 pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data) {
1193 return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL,
1194 (pkgmgr_pkg_size_info_receive_cb)event_cb,
1195 user_data, getuid());
1198 API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc,
1199 const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb,
1200 void *user_data, uid_t uid) {
1201 if (pc == nullptr || pkgid == nullptr || event_cb == nullptr) {
1202 _E("invalid parameter");
1203 return PKGMGR_R_EINVAL;
1207 if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0)
1208 get_type = PM_GET_TOTAL_PKG_SIZE_INFO;
1210 get_type = PM_GET_PKG_SIZE_INFO;
1212 auto* con = static_cast<Connector*>(pc);
1213 if (con->GetPcType() != PC_REQUEST) {
1214 _E("client type is not PC_REQUEST");
1215 return PKGMGR_R_EINVAL;
1218 auto* proxy = con->GetInfoProxy();
1219 if (proxy == nullptr)
1220 return PKGMGR_R_EIO;
1222 const auto& receiver = con->GetSignalReceiver();
1223 std::string req_key;
1224 int ret = proxy->GetSize(uid, pkgid, get_type, req_key);
1225 if (ret != PKGMGR_R_OK)
1228 receiver->AddEventHandler(req_key, event_cb, pc, user_data);
1233 API int pkgmgr_client_generate_license_request(pkgmgr_client *pc,
1234 const char *resp_data, char **req_data, char **license_url) {
1235 if (pc == nullptr || resp_data == nullptr || req_data == nullptr ||
1236 license_url == nullptr) {
1237 _E("invalid parameter");
1238 return PKGMGR_R_EINVAL;
1241 auto* con = static_cast<Connector*>(pc);
1242 if (con->GetPcType() != PC_REQUEST) {
1243 _E("client type is not PC_REQUEST");
1244 return PKGMGR_R_EINVAL;
1247 auto* proxy = con->GetAdminProxy();
1248 if (proxy == nullptr)
1249 return PKGMGR_R_EIO;
1253 std::string req_key;
1254 int ret = proxy->GenerateLicenseRequest(resp_data, req_key);
1255 if (ret != PKGMGR_R_OK)
1258 ret = GetGenerateLicenseResult(pc, req_key, data, url);
1259 if (ret != PKGMGR_R_OK)
1262 *req_data = strdup(data.c_str());
1263 *license_url = strdup(url.c_str());
1267 API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) {
1268 if (pc == nullptr || resp_data == nullptr) {
1269 _E("invalid parameter");
1270 return PKGMGR_R_EINVAL;
1273 auto* con = static_cast<Connector*>(pc);
1274 if (con->GetPcType() != PC_REQUEST) {
1275 _E("client type is not PC_REQUEST");
1276 return PKGMGR_R_EINVAL;
1279 auto* proxy = con->GetAdminProxy();
1280 if (proxy == nullptr)
1281 return PKGMGR_R_EIO;
1283 std::string req_key;
1284 int ret = proxy->RegisterLicense(resp_data, req_key);
1291 return GetDelayedResult(pc, req_key);
1294 API int pkgmgr_client_decrypt_package(pkgmgr_client *pc,
1295 const char *drm_file_path, const char *decrypted_file_path) {
1296 if (pc == nullptr || drm_file_path == nullptr ||
1297 decrypted_file_path == nullptr) {
1298 _E("invalid parameter");
1299 return PKGMGR_R_EINVAL;
1302 auto* con = static_cast<Connector*>(pc);
1303 if (con->GetPcType() != PC_REQUEST) {
1304 _E("client type is not PC_REQUEST");
1305 return PKGMGR_R_EINVAL;
1308 auto* proxy = con->GetAdminProxy();
1309 if (proxy == nullptr)
1310 return PKGMGR_R_EIO;
1312 std::string req_key;
1313 int ret = proxy->DecryptPackage(drm_file_path, decrypted_file_path, req_key);
1320 return GetDelayedResult(pc, req_key);
1323 API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid) {
1324 return pkgmgr_client_usr_enable_splash_screen(pc, appid, getuid());
1327 API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc,
1328 const char *appid, uid_t uid) {
1329 if (pc == nullptr || appid == nullptr) {
1330 _E("Invalid parameter");
1331 return PKGMGR_R_EINVAL;
1334 auto* con = static_cast<Connector*>(pc);
1335 auto* proxy = con->GetAdminProxy();
1336 if (proxy == nullptr)
1337 return PKGMGR_R_EIO;
1339 return proxy->EnableAppSplashScreen(uid, appid);
1342 API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc,
1343 const char *appid) {
1344 return pkgmgr_client_usr_disable_splash_screen(pc, appid,
1348 API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc,
1349 const char *appid, uid_t uid) {
1350 if (pc == nullptr || appid == nullptr) {
1351 _E("Invalid parameter");
1352 return PKGMGR_R_EINVAL;
1355 auto* con = static_cast<Connector*>(pc);
1356 auto* proxy = con->GetAdminProxy();
1357 if (proxy == nullptr)
1358 return PKGMGR_R_EIO;
1360 return proxy->DisableAppSplashScreen(uid, appid);
1363 API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc,
1364 const char *pkgid, int mode, uid_t uid) {
1365 if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0 || mode <= 0) {
1366 _E("invalid parameter");
1367 return PKGMGR_R_EINVAL;
1373 API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc,
1374 const char *pkgid, int mode) {
1375 return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode,
1379 API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc,
1380 const char *pkgid, int mode, uid_t uid) {
1381 if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0 || mode <= 0) {
1382 _E("invalid parameter");
1383 return PKGMGR_R_EINVAL;
1389 API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc,
1390 const char *pkgid, int mode) {
1391 return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode,
1395 API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc,
1396 const char *pkgid, int *mode, uid_t uid) {
1397 if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0) {
1398 _E("invalid parameter");
1399 return PKGMGR_R_EINVAL;
1405 API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc,
1406 const char *pkgid, int *mode) {
1407 return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode,
1411 API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode,
1413 if (pc == nullptr) {
1414 _E("invalid parameter");
1415 return PKGMGR_R_EINVAL;
1421 API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode) {
1422 return pkgmgr_client_usr_set_restriction_mode(pc, mode, getuid());
1425 API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode,
1427 if (pc == nullptr) {
1428 _E("invalid parameter");
1429 return PKGMGR_R_EINVAL;
1435 API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode) {
1436 return pkgmgr_client_usr_unset_restriction_mode(pc, mode, getuid());
1439 API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc,
1440 int *mode, uid_t uid) {
1441 if (pc == nullptr || mode == nullptr) {
1442 _E("invalid parameter");
1443 return PKGMGR_R_EINVAL;
1451 API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode) {
1452 return pkgmgr_client_usr_get_restriction_mode(pc, mode, getuid());
1455 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path) {
1456 if (pkg_path == nullptr) {
1457 _E("invalid parameter");
1461 std::string type = pkgmgr::client::GetTypeFromPath(pkg_path);
1463 _E("invalid package type");
1467 pkg_plugin_set* plugin_set = pkgmgr::client::LoadPluginSet(type);
1469 _E("failed to load library for %s", type.c_str());
1473 package_manager_pkg_detail_info_t* info =
1474 reinterpret_cast<package_manager_pkg_detail_info_t*>(
1475 calloc(1, sizeof(package_manager_pkg_detail_info_t)));
1477 _E("out of memory");
1481 int r = plugin_set->get_pkg_detail_info_from_package(pkg_path, info);
1483 _E("failed to get package detail info");
1491 API int pkgmgr_client_free_pkginfo(pkgmgr_info *info) {
1492 package_manager_pkg_detail_info_t *pkg_info =
1493 reinterpret_cast<package_manager_pkg_detail_info_t*>(info);
1494 if (pkg_info == nullptr) {
1495 _E("invalid parameter");
1496 return PKGMGR_R_EINVAL;
1499 g_list_free_full(pkg_info->privilege_list, free);
1500 free(pkg_info->icon_buf);
1506 API int pkgmgr_client_usr_set_app_label(pkgmgr_client *pc, char *appid,
1507 char *label, uid_t uid) {
1508 if (pc == nullptr || appid == nullptr || label == nullptr) {
1509 _E("Invalid parameter");
1510 return PKGMGR_R_EINVAL;
1513 auto* con = static_cast<Connector*>(pc);
1514 auto* proxy = con->GetAdminProxy();
1515 if (proxy == nullptr)
1516 return PKGMGR_R_EIO;
1518 std::string req_key;
1519 int ret = proxy->SetAppLabel(uid, appid, label, req_key);
1526 return GetDelayedResult(pc, req_key);
1529 API int pkgmgr_client_set_app_label(pkgmgr_client *pc, char *appid, char *label) {
1530 return pkgmgr_client_usr_set_app_label(pc, appid, label, getuid());
1533 API int pkgmgr_client_usr_set_app_icon(pkgmgr_client *pc, char *appid,
1534 char *icon_path, uid_t uid) {
1535 if (pc == nullptr || appid == nullptr || icon_path == nullptr) {
1536 _E("Invalid parameter");
1537 return PKGMGR_R_EINVAL;
1540 auto* con = static_cast<Connector*>(pc);
1541 auto* proxy = con->GetAdminProxy();
1542 if (proxy == nullptr)
1543 return PKGMGR_R_EIO;
1545 std::string req_key;
1546 int ret = proxy->SetAppIcon(uid, appid, icon_path, req_key);
1553 return GetDelayedResult(pc, req_key);
1556 API int pkgmgr_client_set_app_icon(pkgmgr_client *pc, char *appid, char *icon_path) {
1557 return pkgmgr_client_usr_set_app_icon(pc, appid, icon_path, getuid());
1560 API int pkgmgr_client_set_debug_mode(pkgmgr_client *pc, bool debug_mode) {
1561 if (pc == nullptr) {
1562 _E("invalid parameter");
1563 return PKGMGR_R_EINVAL;
1566 auto* con = static_cast<Connector*>(pc);
1568 con->SetDebugMode();
1573 API int pkgmgr_client_set_skip_optimization(pkgmgr_client *pc, bool skip_optimization) {
1574 if (pc == nullptr) {
1575 _E("invalid parameter");
1576 return PKGMGR_R_EINVAL;
1579 auto* con = static_cast<Connector*>(pc);
1580 if (skip_optimization)
1581 con->SetSkipOptimization();
1586 API int pkgmgr_client_usr_migrate_external_image(pkgmgr_client *pc,
1587 const char *pkgid, uid_t uid) {
1588 if (pc == nullptr) {
1589 _E("invalid parameter");
1590 return PKGMGR_R_EINVAL;
1593 auto* con = static_cast<Connector*>(pc);
1594 auto* proxy = con->GetAdminProxy();
1595 if (proxy == nullptr)
1596 return PKGMGR_R_EIO;
1598 return proxy->MigrateExternalImage(uid, pkgid);
1601 API int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc,
1602 const char *src_path, const char *dest_path) {
1603 if (pc == nullptr || src_path == nullptr) {
1604 _E("invalid parameter");
1605 return PKGMGR_R_EINVAL;
1608 auto* con = static_cast<Connector*>(pc);
1609 con->GetResCopyPath().emplace_back(src_path, dest_path ? dest_path: "");
1614 API int pkgmgr_client_res_copy(pkgmgr_client *pc,
1615 pkgmgr_res_handler event_cb, void *user_data) {
1616 if (pc == nullptr || event_cb == nullptr) {
1617 _E("invalid parameter");
1618 return PKGMGR_R_EINVAL;
1621 auto* con = static_cast<Connector*>(pc);
1622 auto* proxy = con->GetAdminProxy();
1623 if (proxy == nullptr)
1624 return PKGMGR_R_EIO;
1626 const auto& receiver = con->GetSignalReceiver();
1628 std::string req_key;
1629 int ret = proxy->ResCopy(con->GetResCopyPath(), req_key);
1630 if (ret != PKGMGR_R_OK)
1633 return receiver->AddEventHandler(req_key, event_cb, user_data);
1636 API int pkgmgr_client_add_res_create_dir_path(pkgmgr_client *pc,
1637 const char *dir_path) {
1638 if (pc == nullptr || dir_path == nullptr) {
1639 _E("invalid parameter");
1640 return PKGMGR_R_EINVAL;
1643 auto* con = static_cast<Connector*>(pc);
1644 con->GetResCreateDir().emplace_back(dir_path);
1649 API int pkgmgr_client_res_create_dir(pkgmgr_client *pc,
1650 pkgmgr_res_handler event_cb, void *user_data) {
1651 if (pc == nullptr || event_cb == nullptr) {
1652 _E("invalid parameter");
1653 return PKGMGR_R_EINVAL;
1656 auto* con = static_cast<Connector*>(pc);
1657 auto* proxy = con->GetAdminProxy();
1658 if (proxy == nullptr)
1659 return PKGMGR_R_EIO;
1661 const auto& receiver = con->GetSignalReceiver();
1663 std::string req_key;
1664 int ret = proxy->ResCreateDir(con->GetResCreateDir(), req_key);
1665 if (ret != PKGMGR_R_OK)
1668 return receiver->AddEventHandler(req_key, event_cb, user_data);
1671 API int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc,
1672 const char *res_path) {
1673 if (pc == nullptr || res_path == nullptr) {
1674 _E("invalid parameter");
1675 return PKGMGR_R_EINVAL;
1678 auto* con = static_cast<Connector*>(pc);
1679 con->GetResRemovePath().push_back(res_path);
1684 API int pkgmgr_client_res_remove(pkgmgr_client *pc,
1685 pkgmgr_res_handler event_cb, void *user_data) {
1686 if (pc == nullptr || event_cb == nullptr) {
1687 _E("invalid parameter");
1688 return PKGMGR_R_EINVAL;
1691 auto* con = static_cast<Connector*>(pc);
1692 auto* proxy = con->GetAdminProxy();
1693 if (proxy == nullptr)
1694 return PKGMGR_R_EIO;
1696 const auto& receiver = con->GetSignalReceiver();
1698 std::string req_key;
1699 int ret = proxy->ResRemove(con->GetResRemovePath(), req_key);
1700 if (ret != PKGMGR_R_OK)
1703 return receiver->AddEventHandler(req_key, event_cb, user_data);
1706 API int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid) {
1707 return pkgmgr_client_res_usr_uninstall(pc, pkgid, getuid());
1710 API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid,
1712 if (pc == nullptr || pkgid == nullptr) {
1713 _E("invalid parameter");
1714 return PKGMGR_R_EINVAL;
1717 auto* con = static_cast<Connector*>(pc);
1718 auto* proxy = con->GetAdminProxy();
1719 if (proxy == nullptr)
1720 return PKGMGR_R_EIO;
1722 std::string req_key;
1723 return proxy->ResUninstall(uid, pkgid, req_key);
1726 API pkgmgr_res_event_info *pkgmgr_res_event_info_new() {
1727 pkgmgr_res_event_info* info =
1728 reinterpret_cast<pkgmgr_res_event_info*>(
1729 new rpc_port::PkgSignal::ExtraData);
1731 _E("Out of memory");
1737 API int pkgmgr_res_event_info_free(pkgmgr_res_event_info *info) {
1739 _E("invalid parameter");
1740 return PKGMGR_R_EINVAL;
1742 rpc_port::PkgSignal::ExtraData* event_info =
1743 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(info);
1749 API int pkgmgr_res_event_info_set_error_code(pkgmgr_res_event_info *handle, int error_code) {
1751 _E("invalid parameter");
1752 return PKGMGR_R_EINVAL;
1755 rpc_port::PkgSignal::ExtraData* event_info =
1756 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(handle);
1757 event_info->SetErrCode(error_code);
1762 API int pkgmgr_res_event_info_get_error_code(pkgmgr_res_event_info *handle, int *error_code) {
1764 _E("invalid parameter");
1765 return PKGMGR_R_EINVAL;
1768 rpc_port::PkgSignal::ExtraData* event_info =
1769 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(handle);
1770 *error_code = event_info->GetErrCode();
1775 API int pkgmgr_res_event_info_add_path_state(pkgmgr_res_event_info *handle,
1776 const char *path, pkgmgr_res_event_path_state state) {
1777 if (!handle || !path) {
1778 _E("invalid parameter");
1779 return PKGMGR_R_EINVAL;
1782 rpc_port::PkgSignal::ExtraData* event_info =
1783 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(handle);
1785 auto paths = event_info->GetPaths();
1786 paths.emplace_back(path, state);
1787 event_info->SetPaths(std::move(paths));
1792 API int pkgmgr_res_event_info_foreach_path(pkgmgr_res_event_info *handle,
1793 pkgmgr_res_event_path_cb callback, void *user_data) {
1794 if (!handle || !callback) {
1795 _E("invalid parameter");
1796 return PKGMGR_R_EINVAL;
1799 rpc_port::PkgSignal::ExtraData* event_info =
1800 reinterpret_cast<rpc_port::PkgSignal::ExtraData*>(handle);
1802 for (const auto& p : event_info->GetPaths()) {
1803 if (callback(p.GetPath().c_str(),
1804 static_cast<pkgmgr_res_event_path_state>(p.GetState()), user_data) < 0)