From: Ilho Kim Date: Thu, 11 Apr 2024 08:45:56 +0000 (+0900) Subject: Apply try-catch where exception can be occured X-Git-Tag: accepted/tizen/unified/20240413.101709~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=015dd3cd87cb07a074acbeacf73138c248dd2195;p=platform%2Fcore%2Fappfw%2Fslp-pkgmgr.git Apply try-catch where exception can be occured Change-Id: Ic4fc7bcea0ce79a68afe97607bd66c821b87a6c0 Signed-off-by: Ilho Kim --- diff --git a/client/src/api_stub.cc b/client/src/api_stub.cc index f875642..91c060d 100644 --- a/client/src/api_stub.cc +++ b/client/src/api_stub.cc @@ -52,24 +52,29 @@ static int GetDelayedResult(pkgmgr_client *pc, const std::string& req_key) { return PKGMGR_R_EINVAL; } - auto* proxy = con->GetDelayedResultProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - int retry_cnt = 0; - int ret = 0; - do { - if (proxy->GetResult(req_key, ret) == PKGMGR_R_OK) - return ret; + try { + auto* proxy = con->GetDelayedResultProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + int retry_cnt = 0; + int ret = 0; + do { + if (proxy->GetResult(req_key, ret) == PKGMGR_R_OK) + return ret; - _E("Failed to get result sleep and retry[%d/%d]", - retry_cnt, CONNECTION_RETRY_MAX); - usleep(CONNECTION_WAIT_USEC); - retry_cnt++; - } while (retry_cnt <= CONNECTION_RETRY_MAX); + _E("Failed to get result sleep and retry[%d/%d]", + retry_cnt, CONNECTION_RETRY_MAX); + usleep(CONNECTION_WAIT_USEC); + retry_cnt++; + } while (retry_cnt <= CONNECTION_RETRY_MAX); - _E("Failed to get result"); - return PKGMGR_R_ERROR; + _E("Failed to get result"); + return PKGMGR_R_ERROR; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } static int ResultGetSizeSync(pkgmgr_client *pc, const std::string& req_key) { @@ -84,37 +89,42 @@ static int ResultGetSizeSync(pkgmgr_client *pc, const std::string& req_key) { return PKGMGR_R_EINVAL; } - auto* proxy = con->GetInfoProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - int retry_cnt = 0; - int ret = PKGMGR_R_ECOMM; - long long size_info = 0; - do { - if (proxy->GetSizeSyncResult(req_key, ret, size_info) == PKGMGR_R_OK) { - if (ret != PKGMGR_R_OK) { - _E("request result failed: %d", ret); - return ret; - } - - if (size_info < 0) { - _E("invalid size_info=(%lld)", size_info); - return -1; + try { + auto* proxy = con->GetInfoProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + int retry_cnt = 0; + int ret = PKGMGR_R_ECOMM; + long long size_info = 0; + do { + if (proxy->GetSizeSyncResult(req_key, ret, size_info) == PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) { + _E("request result failed: %d", ret); + return ret; + } + + if (size_info < 0) { + _E("invalid size_info=(%lld)", size_info); + return -1; + } + + _D("size_info(%lld), return size(%d)", size_info, ret); + return size_info; } - _D("size_info(%lld), return size(%d)", size_info, ret); - return size_info; - } + _E("Failed to get result sleep and retry[%d/%d]", + retry_cnt, CONNECTION_RETRY_MAX); + usleep(CONNECTION_WAIT_USEC); + retry_cnt++; + } while (retry_cnt <= CONNECTION_RETRY_MAX); - _E("Failed to get result sleep and retry[%d/%d]", - retry_cnt, CONNECTION_RETRY_MAX); - usleep(CONNECTION_WAIT_USEC); - retry_cnt++; - } while (retry_cnt <= CONNECTION_RETRY_MAX); - - _E("Failed to get result"); - return ret; + _E("Failed to get result"); + return ret; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } static int GetGenerateLicenseResult(pkgmgr_client *pc, @@ -130,25 +140,30 @@ static int GetGenerateLicenseResult(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - int retry_cnt = 0; - int ret = PKGMGR_R_ECOMM; - do { - if (proxy->GetGenerateLicenseResult(req_key, - ret, reqData, licenseUrl) == PKGMGR_R_OK) - return ret; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + int retry_cnt = 0; + int ret = PKGMGR_R_ECOMM; + do { + if (proxy->GetGenerateLicenseResult(req_key, + ret, reqData, licenseUrl) == PKGMGR_R_OK) + return ret; - _E("Failed to get result sleep and retry[%d/%d]", - retry_cnt, CONNECTION_RETRY_MAX); - usleep(CONNECTION_WAIT_USEC); - retry_cnt++; - } while (retry_cnt <= CONNECTION_RETRY_MAX); + _E("Failed to get result sleep and retry[%d/%d]", + retry_cnt, CONNECTION_RETRY_MAX); + usleep(CONNECTION_WAIT_USEC); + retry_cnt++; + } while (retry_cnt <= CONNECTION_RETRY_MAX); - _E("Failed to get result"); - return ret; + _E("Failed to get result"); + return ret; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } static inline uid_t GetUid() { @@ -209,22 +224,27 @@ API int pkgmgr_client_usr_install_packages(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - std::vector pkgs; - for (int i = 0; i < n_pkgs; i++) - pkgs.push_back(pkg_paths[i]); - - int ret = proxy->InstallPkgs(uid, pkgs, con->GetArgv(), - con->GenerateRequestId(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector pkgs; + for (int i = 0; i < n_pkgs; i++) + pkgs.push_back(pkg_paths[i]); + + int ret = proxy->InstallPkgs(uid, pkgs, con->GetArgv(), + con->GenerateRequestId(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_install_packages(pkgmgr_client *pc, @@ -271,18 +291,23 @@ API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, con->SetTepArgs(); } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - int ret = proxy->Install(uid, pkg_type ? pkg_type : "", pkg_path, con->GetArgv(), - con->GenerateRequestId(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + int ret = proxy->Install(uid, pkg_type ? pkg_type : "", pkg_path, con->GetArgv(), + con->GenerateRequestId(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type, @@ -306,17 +331,22 @@ API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->Reinstall(uid, pkgid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->Reinstall(uid, pkgid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_uninstall_packages(pkgmgr_client *pc, @@ -340,21 +370,26 @@ API int pkgmgr_client_usr_uninstall_packages(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - std::vector pkgs; - for (int i = 0; i < n_pkgs; i++) - pkgs.push_back(pkgids[i]); + std::string req_key; + std::vector pkgs; + for (int i = 0; i < n_pkgs; i++) + pkgs.push_back(pkgids[i]); - int ret = proxy->UninstallPkgs(uid, pkgs, req_key); - if (ret != PKGMGR_R_OK) - return ret; + int ret = proxy->UninstallPkgs(uid, pkgs, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type, @@ -378,17 +413,22 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->Uninstall(uid, pkgid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->Uninstall(uid, pkgid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_listen_res_status(pkgmgr_client *pc, @@ -403,7 +443,7 @@ API int pkgmgr_client_listen_res_status(pkgmgr_client *pc, const auto& receiver = con->GetSignalReceiver(); return receiver->AddEventHandler("", event_cb, data); } catch (...) { - _E("exception occured"); + _E("Exception occured"); return PKGMGR_R_ERROR; } } @@ -428,28 +468,33 @@ API int pkgmgr_client_usr_mount_install_packages(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector pkgs; + for (int i = 0; i < n_pkgs; i++) { + if (access(pkg_paths[i], F_OK) != 0) { + _E("failed to access: %s", pkg_paths[i]); + return PKGMGR_R_EINVAL; + } - std::string req_key; - std::vector pkgs; - for (int i = 0; i < n_pkgs; i++) { - if (access(pkg_paths[i], F_OK) != 0) { - _E("failed to access: %s", pkg_paths[i]); - return PKGMGR_R_EINVAL; + pkgs.push_back(pkg_paths[i]); } - pkgs.push_back(pkg_paths[i]); - } - - int ret = proxy->MountInstallPkgs(uid, pkgs, con->GenerateRequestId(), - req_key); - if (ret != PKGMGR_R_OK) - return ret; + int ret = proxy->MountInstallPkgs(uid, pkgs, con->GenerateRequestId(), + req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_mount_install_packages(pkgmgr_client *pc, @@ -497,18 +542,23 @@ API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, con->SetTepArgs(); } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - int ret = proxy->MountInstall(uid, pkg_type ? pkg_type : "", pkg_path, - con->GetArgv(), con->GenerateRequestId(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + int ret = proxy->MountInstall(uid, pkg_type ? pkg_type : "", pkg_path, + con->GetArgv(), con->GenerateRequestId(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type, @@ -536,17 +586,22 @@ API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->Move(uid, pkgid, move_type, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->Move(uid, pkgid, move_type, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc, @@ -568,19 +623,24 @@ API int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + int ret = proxy->RegisterPkgUpdateInfo(uid, update_info->pkgid, + update_info->version, update_info->type, req_key); + if (ret != 0) { + _E("Request fail"); + return ret; + } - std::string req_key; - int ret = proxy->RegisterPkgUpdateInfo(uid, update_info->pkgid, - update_info->version, update_info->type, req_key); - if (ret != 0) { - _E("Request fail"); - return ret; + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; } - - return GetDelayedResult(pc, req_key); } API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc, @@ -596,19 +656,24 @@ API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->UnregisterPkgUpdateInfo(uid, pkgid, req_key); + std::string req_key; + int ret = proxy->UnregisterPkgUpdateInfo(uid, pkgid, req_key); - if (ret != 0) { - _E("Request fail"); - return ret; - } + if (ret != 0) { + _E("Request fail"); + return ret; + } - return GetDelayedResult(pc, req_key); + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc, @@ -629,12 +694,17 @@ API int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - return proxy->UnregisterAllPkgUpdateInfo(uid, req_key); + std::string req_key; + return proxy->UnregisterAllPkgUpdateInfo(uid, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc) { @@ -649,12 +719,22 @@ API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - std::string req_key; - return proxy->EnablePkgs(uid, { pkgid }, req_key); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + return proxy->EnablePkgs(uid, { pkgid }, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type, @@ -676,22 +756,27 @@ API int pkgmgr_client_usr_activate_packages(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - std::vector vec; - for (int i = 0; i < n_pkgs; i++) { - vec.push_back(pkgids[i]); - } + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector vec; + for (int i = 0; i < n_pkgs; i++) { + vec.push_back(pkgids[i]); + } - int ret = proxy->EnablePkgs(uid, std::move(vec), req_key); - if (ret != PKGMGR_R_OK) - return ret; + int ret = proxy->EnablePkgs(uid, std::move(vec), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, data); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_activate_packages(pkgmgr_client *pc, @@ -709,12 +794,22 @@ API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } + + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - return proxy->DisablePkgs(uid, { pkgid }, req_key); + std::string req_key; + return proxy->DisablePkgs(uid, { pkgid }, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type, @@ -736,21 +831,26 @@ API int pkgmgr_client_usr_deactivate_packages(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector vec; + for (int i = 0; i < n_pkgs; i++) { + vec.push_back(pkgids[i]); + } + int ret = proxy->DisablePkgs(uid, std::move(vec), req_key); + if (ret != PKGMGR_R_OK) + return ret; - std::string req_key; - std::vector vec; - for (int i = 0; i < n_pkgs; i++) { - vec.push_back(pkgids[i]); + return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; } - int ret = proxy->DisablePkgs(uid, std::move(vec), req_key); - if (ret != PKGMGR_R_OK) - return ret; - - return receiver->AddEventHandler(req_key, event_cb, data); } API int pkgmgr_client_deactivate_packages(pkgmgr_client *pc, @@ -773,17 +873,22 @@ API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->EnableApp(uid, appid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->EnableApp(uid, appid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, @@ -805,22 +910,27 @@ API int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - std::vector vec; - for (int i = 0; i < n_apps; i++) { - vec.push_back(appids[i]); - } + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector vec; + for (int i = 0; i < n_apps; i++) { + vec.push_back(appids[i]); + } - int ret = proxy->EnableApps(uid, std::move(vec), req_key); - if (ret != PKGMGR_R_OK) - return ret; + int ret = proxy->EnableApps(uid, std::move(vec), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids, @@ -842,17 +952,22 @@ API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->EnableGlobalAppForUid(uid, appid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->EnableGlobalAppForUid(uid, appid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, @@ -868,17 +983,22 @@ API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->DisableApp(uid, appid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->DisableApp(uid, appid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, @@ -901,22 +1021,27 @@ API int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string req_key; - std::vector vec; - for (int i = 0; i < n_apps; i++) { - vec.push_back(appids[i]); - } + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector vec; + for (int i = 0; i < n_apps; i++) { + vec.push_back(appids[i]); + } - int ret = proxy->DisableApps(uid, std::move(vec), req_key); - if (ret != PKGMGR_R_OK) - return ret; + int ret = proxy->DisableApps(uid, std::move(vec), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids, @@ -938,17 +1063,22 @@ API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->DisableGlobalAppForUid(uid, appid, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->DisableGlobalAppForUid(uid, appid, req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, app_event_cb, data); + return receiver->AddEventHandler(req_key, app_event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type, @@ -971,11 +1101,16 @@ API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - return proxy->ClearData(uid, pkgid); + return proxy->ClearData(uid, pkgid); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_usr_clear_user_data_with_path(pkgmgr_client *pc, @@ -993,11 +1128,16 @@ API int pkgmgr_client_usr_clear_user_data_with_path(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - return proxy->ClearDataWithPath(uid, pkgid, file_path); + return proxy->ClearDataWithPath(uid, pkgid, file_path); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_clear_user_data_with_path(pkgmgr_client *pc, const char *pkg_type, @@ -1029,7 +1169,7 @@ API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb, const auto& receiver = con->GetSignalReceiver(); return receiver->AddEventHandler("", event_cb, data); } catch (...) { - _E("exception occured"); + _E("Exception occured"); return PKGMGR_R_ERROR; } } @@ -1051,7 +1191,7 @@ API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, const auto& receiver = con->GetSignalReceiver(); return receiver->AddEventHandler("", app_event_cb, data); } catch (...) { - _E("exception occured"); + _E("Exception occured"); return PKGMGR_R_ERROR; } } @@ -1089,38 +1229,54 @@ API int pkgmgr_client_usr_request_service( event_cb, data, uid); } case PM_REQUEST_GET_SIZE: { - auto* con = static_cast(pc); - auto* proxy = con->GetInfoProxy(); - std::string req_key; - int ret = proxy->GetSizeSync(uid, pkgid, service_mode, req_key); - if (ret != PKGMGR_R_OK) - return ret; - - return ResultGetSizeSync(pc, req_key); + try { + auto* con = static_cast(pc); + auto* proxy = con->GetInfoProxy(); + std::string req_key; + int ret = proxy->GetSizeSync(uid, pkgid, service_mode, req_key); + if (ret != PKGMGR_R_OK) + return ret; + + return ResultGetSizeSync(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } case PM_REQUEST_KILL_APP: { - auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - int pid = 0; - int ret = proxy->Kill(uid, pkgid, pid); - *(int *)data = pid; + try { + auto* con = static_cast(pc); + auto* proxy = con->GetAdminProxy(); + int pid = 0; + int ret = proxy->Kill(uid, pkgid, pid); + *(int *)data = pid; - return ret; + return ret; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } case PM_REQUEST_CHECK_APP: { - auto* con = static_cast(pc); - auto* proxy = con->GetInfoProxy(); - int pid = 0; - int ret = proxy->Check(uid, pkgid, pid); - *(int *)data = pid; + try { + auto* con = static_cast(pc); + auto* proxy = con->GetInfoProxy(); + int pid = 0; + int ret = proxy->Check(uid, pkgid, pid); + *(int *)data = pid; - return ret; + return ret; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } default: _E("Wrong Request"); break; } - return 0; + + return PKGMGR_R_ERROR; } API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) { @@ -1129,15 +1285,20 @@ API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) { return PKGMGR_R_EINVAL; } - auto* con = new Connector(PC_REQUEST); - auto* proxy = con->GetCacheProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* con = new Connector(PC_REQUEST); + auto* proxy = con->GetCacheProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - int ret = proxy->ClearCache(uid, pkgid); - delete con; + int ret = proxy->ClearCache(uid, pkgid); + delete con; - return ret; + return ret; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_clear_cache_dir(const char *pkgid) { @@ -1180,17 +1341,23 @@ API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetInfoProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetInfoProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->GetSize(uid, pkgid, get_type, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->GetSize(uid, pkgid, get_type, req_key); + if (ret != PKGMGR_R_OK) + return ret; + + return receiver->AddEventHandler(req_key, event_cb, data); - return receiver->AddEventHandler(req_key, event_cb, data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, @@ -1235,19 +1402,24 @@ API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetInfoProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetInfoProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->GetSize(uid, pkgid, get_type, req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->GetSize(uid, pkgid, get_type, req_key); + if (ret != PKGMGR_R_OK) + return ret; - receiver->AddEventHandler(req_key, event_cb, pc, user_data); + receiver->AddEventHandler(req_key, event_cb, pc, user_data); - return PKGMGR_R_OK; + return PKGMGR_R_OK; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, @@ -1264,24 +1436,29 @@ API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; - - std::string data; - std::string url; - std::string req_key; - int ret = proxy->GenerateLicenseRequest(resp_data, req_key); - if (ret != PKGMGR_R_OK) - return ret; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string data; + std::string url; + std::string req_key; + int ret = proxy->GenerateLicenseRequest(resp_data, req_key); + if (ret != PKGMGR_R_OK) + return ret; - ret = GetGenerateLicenseResult(pc, req_key, data, url); - if (ret != PKGMGR_R_OK) - return ret; + ret = GetGenerateLicenseResult(pc, req_key, data, url); + if (ret != PKGMGR_R_OK) + return ret; - *req_data = strdup(data.c_str()); - *license_url = strdup(url.c_str()); - return PKGMGR_R_OK; + *req_data = strdup(data.c_str()); + *license_url = strdup(url.c_str()); + return PKGMGR_R_OK; + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) { @@ -1296,19 +1473,24 @@ API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->RegisterLicense(resp_data, req_key); + std::string req_key; + int ret = proxy->RegisterLicense(resp_data, req_key); - if (ret != 0) { - _E("Request fail"); - return ret; - } + if (ret != 0) { + _E("Request fail"); + return ret; + } - return GetDelayedResult(pc, req_key); + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, @@ -1325,19 +1507,24 @@ API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->DecryptPackage(drm_file_path, decrypted_file_path, req_key); + std::string req_key; + int ret = proxy->DecryptPackage(drm_file_path, decrypted_file_path, req_key); - if (ret != 0) { - _E("Request fail"); - return ret; - } + if (ret != 0) { + _E("Request fail"); + return ret; + } - return GetDelayedResult(pc, req_key); + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid) { @@ -1352,11 +1539,21 @@ API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - return proxy->EnableAppSplashScreen(uid, appid); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->EnableAppSplashScreen(uid, appid); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc, @@ -1373,11 +1570,21 @@ API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } + + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - return proxy->DisableAppSplashScreen(uid, appid); + return proxy->DisableAppSplashScreen(uid, appid); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, @@ -1531,19 +1738,29 @@ API int pkgmgr_client_usr_set_app_label(pkgmgr_client *pc, char *appid, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - std::string req_key; - int ret = proxy->SetAppLabel(uid, appid, label, req_key); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - if (ret != 0) { - _E("Request fail"); - return ret; - } + std::string req_key; + int ret = proxy->SetAppLabel(uid, appid, label, req_key); - return GetDelayedResult(pc, req_key); + if (ret != 0) { + _E("Request fail"); + return ret; + } + + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_set_app_label(pkgmgr_client *pc, char *appid, char *label) { @@ -1558,19 +1775,29 @@ API int pkgmgr_client_usr_set_app_icon(pkgmgr_client *pc, char *appid, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - std::string req_key; - int ret = proxy->SetAppIcon(uid, appid, icon_path, req_key); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - if (ret != 0) { - _E("Request fail"); - return ret; - } + std::string req_key; + int ret = proxy->SetAppIcon(uid, appid, icon_path, req_key); - return GetDelayedResult(pc, req_key); + if (ret != 0) { + _E("Request fail"); + return ret; + } + + return GetDelayedResult(pc, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_set_app_icon(pkgmgr_client *pc, char *appid, char *icon_path) { @@ -1611,11 +1838,21 @@ API int pkgmgr_client_usr_migrate_external_image(pkgmgr_client *pc, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - return proxy->MigrateExternalImage(uid, pkgid); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->MigrateExternalImage(uid, pkgid); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc, @@ -1644,18 +1881,23 @@ API int pkgmgr_client_res_copy(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->ResCopy(con->GetResCopyPath(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->ResCopy(con->GetResCopyPath(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, user_data); + return receiver->AddEventHandler(req_key, event_cb, user_data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_add_res_create_dir_path(pkgmgr_client *pc, @@ -1684,18 +1926,23 @@ API int pkgmgr_client_res_create_dir(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->ResCreateDir(con->GetResCreateDir(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->ResCreateDir(con->GetResCreateDir(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, user_data); + return receiver->AddEventHandler(req_key, event_cb, user_data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc, @@ -1724,18 +1971,23 @@ API int pkgmgr_client_res_remove(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - const auto& receiver = con->GetSignalReceiver(); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + try { + const auto& receiver = con->GetSignalReceiver(); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; - std::string req_key; - int ret = proxy->ResRemove(con->GetResRemovePath(), req_key); - if (ret != PKGMGR_R_OK) - return ret; + std::string req_key; + int ret = proxy->ResRemove(con->GetResRemovePath(), req_key); + if (ret != PKGMGR_R_OK) + return ret; - return receiver->AddEventHandler(req_key, event_cb, user_data); + return receiver->AddEventHandler(req_key, event_cb, user_data); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid) { @@ -1750,12 +2002,22 @@ API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, } auto* con = static_cast(pc); - auto* proxy = con->GetAdminProxy(); - if (proxy == nullptr) - return PKGMGR_R_EIO; + if (con->GetPcType() != PC_REQUEST) { + _E("client type is not PC_REQUEST"); + return PKGMGR_R_EINVAL; + } - std::string req_key; - return proxy->ResUninstall(uid, pkgid, req_key); + try { + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + return proxy->ResUninstall(uid, pkgid, req_key); + } catch (...) { + _E("Exception occured"); + return PKGMGR_R_ESYSTEM; + } } API pkgmgr_res_event_info *pkgmgr_res_event_info_new() { diff --git a/installer/src/control.cc b/installer/src/control.cc index 8c0e8f0..e9f6d30 100644 --- a/installer/src/control.cc +++ b/installer/src/control.cc @@ -386,9 +386,15 @@ int Control::SendSignal(std::string pkg_type, std::string pkgid, auto& req = GetRequest(); std::vector pkgs; pkgs.emplace_back(std::move(pkgid), std::move(appid), std::move(pkg_type)); - signal_->AsyncResult("", req->GetUid(), req->GetSessionId(), std::move(pkgs), - key, val); - return 0; + + try { + signal_->AsyncResult("", req->GetUid(), req->GetSessionId(), std::move(pkgs), + key, val); + return 0; + } catch (...) { + _E("Exception occured"); + return -1; + } } int Control::SendSignals(std::string key, std::string val) { @@ -397,8 +403,14 @@ int Control::SendSignals(std::string key, std::string val) { return -1; } auto& req = GetRequest(); - signal_->AsyncResult("", req->GetUid(), req->GetSessionId(), pkgs_, key, val); - return 0; + + try { + signal_->AsyncResult("", req->GetUid(), req->GetSessionId(), pkgs_, key, val); + return 0; + } catch (...) { + _E("Exception occured"); + return -1; + } } int Control::SendSignalForResource(std::string pkgid, std::string status, @@ -415,9 +427,14 @@ int Control::SendSignalForResource(std::string pkgid, std::string status, return -1; } - signal_->AsyncResultForResource(signal_name, req->GetUid(), - req->GetSessionId(), std::move(pkgid), std::move(status), *event_info); - return 0; + try { + signal_->AsyncResultForResource(signal_name, req->GetUid(), + req->GetSessionId(), std::move(pkgid), std::move(status), *event_info); + return 0; + } catch (...) { + _E("Exception occured"); + return -1; + } } static int __send_signal_to_agent(uid_t uid, void* data, size_t len) { diff --git a/installer/src/request.hh b/installer/src/request.hh index d8e49ad..d9c48d0 100644 --- a/installer/src/request.hh +++ b/installer/src/request.hh @@ -24,8 +24,6 @@ #include #include -#include "PkgSignal.h" - namespace pkgmgr { namespace installer {