diff options
author | jh9216.park <jh9216.park@samsung.com> | 2022-07-21 02:05:49 -0400 |
---|---|---|
committer | jh9216.park <jh9216.park@samsung.com> | 2022-08-29 00:36:32 -0400 |
commit | 665adc112fe531d15f9fa890dae540bacdc234d6 (patch) | |
tree | 10b3059dba4a3d7ff01248418101f5af3da7f5a5 | |
parent | 4d4e89e483c0fc3e4d3b1f24023501d392d17152 (diff) | |
download | slp-pkgmgr-rdtp.tar.gz slp-pkgmgr-rdtp.tar.bz2 slp-pkgmgr-rdtp.zip |
Refactor pkgmgr using TIDLrdtp
Change-Id: I8eaf77636cc56a117c42a2553846f0f61af08188
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
50 files changed, 4395 insertions, 6139 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a6fbfa..2cbea2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,41 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -SET(CMAKE_SKIP_BUILD_RPATH true) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(package-manager C) -INCLUDE(TizenCommon) +PROJECT(package-manager) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") SET(LIBDIR ${LIB_INSTALL_DIR}) SET(INCLUDEDIR "\${prefix}/include") +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") SET(PKGMGR_CLIENT "pkgmgr-client") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -fpic ") +SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 ") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall") - +INCLUDE(TizenCommon) INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(comm) - INCLUDE(FindPkgConfig) +INCLUDE(ApplyPkgConfig) + +PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle) +PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) +PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) +PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0) +PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0) +PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port) +PKG_CHECK_MODULES(CAPI_APPFW_EVENT_DEPS REQUIRED capi-appfw-event) +PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser) +PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info) +PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) +PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime) +PKG_CHECK_MODULES(PLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config) +PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip) ADD_SUBDIRECTORY(installer) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(types) + +ENABLE_TESTING() +SET(TARGET_PKGMGR_UNIT_TEST "pkgmgr-unit-test") +ADD_SUBDIRECTORY(test) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index a59ff50..a61df4f 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -2,30 +2,26 @@ AUX_SOURCE_DIRECTORY(src SRCS) -pkg_check_modules(CLIENT_DEPS REQUIRED - glib-2.0 - gio-2.0 - dlog - pkgmgr-parser - pkgmgr-info - iniparser - xdgmime - libtzplatform-config - minizip) -FOREACH(CLIENT_FLAGS ${CLIENT_DEPS_CFLAGS}) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLIENT_FLAGS}") -ENDFOREACH(CLIENT_FLAGS) - INCLUDE_DIRECTORIES(include) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - ADD_LIBRARY(${PKGMGR_CLIENT} SHARED ${SRCS}) SET_TARGET_PROPERTIES(${PKGMGR_CLIENT} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${PKGMGR_CLIENT} PROPERTIES VERSION ${FULLVER}) -TARGET_LINK_LIBRARIES(${PKGMGR_CLIENT} - pkgmgr-info - ${CLIENT_DEPS_LDFLAGS}) + +APPLY_PKG_CONFIG(${PKGMGR_CLIENT} PUBLIC + GLIB_DEPS + GIO_DEPS + DLOG_DEPS + BUNDLE_DEPS + PKGMGR_PARSER_DEPS + PKGMGR_INFO_DEPS + INIPARSER_DEPS + XDGMIME_DEPS + PLATFORM_CONFIG_DEPS + MINIZIP_DEPS + RPC_PORT_DEPS + CAPI_APPFW_EVENT_DEPS +) CONFIGURE_FILE(pkgmgr.pc.in pkgmgr.pc @ONLY) CONFIGURE_FILE(pkg_path.conf.in pkg_path.conf @ONLY) diff --git a/client/src/api_stub.cc b/client/src/api_stub.cc new file mode 100644 index 0000000..3aa4a73 --- /dev/null +++ b/client/src/api_stub.cc @@ -0,0 +1,1283 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <unistd.h> +#include <tzplatform_config.h> + +#include "package-manager.h" +#include "package-manager-types.h" + +#include "connector.hh" +#include "log.hh" + +#ifdef API +#undef API +#endif +#define API __attribute__ ((visibility("default"))) + +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) + +using namespace pkgmgr::client; + +API pkgmgr_client* pkgmgr_client_new(pkgmgr_client_type pc_type) { + if (pc_type != PC_REQUEST && pc_type != PC_LISTENING) { + _E("invalid parameter"); + return nullptr; + } + + return new Connector(); +} + +API int pkgmgr_client_free(pkgmgr_client* pc) { + if (pc == nullptr) { + _E("invalid argument"); + return PKGMGR_R_EINVAL; + } + + Connector* con = static_cast<Connector*>(pc); + delete con; + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, const char *tep_path, + bool tep_move) { + if (pc == nullptr || tep_path == nullptr) { + _E("invalied parameter"); + return PKGMGR_R_EINVAL; + } + + Connector* con = static_cast<Connector*>(pc); + con->SetTep(tep_path, tep_move); + return PKGMGR_R_OK; +} + +API int pkgmgr_client_usr_install_packages(pkgmgr_client *pc, + const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, + void *data, uid_t uid) { + if (pc == nullptr || pkg_paths == nullptr || n_pkgs < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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 con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_install_packages(pkgmgr_client *pc, + const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, + void *data) { + return pkgmgr_client_usr_install_packages(pc, pkg_paths, n_pkgs, + event_cb, data, getuid()); +} + +API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type, + const char *descriptor_path, const char *pkg_path, + const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path, pkg_path, + optional_data, mode, event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, + const char *descriptor_path, const char *pkg_path, + const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkg_path == nullptr || pkg_type == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + int ret = proxy->Install(uid, pkg_type, pkg_path, con->GetArgv(), + con->GenerateRequestId(), req_key); + if (ret != PKGMGR_R_OK) + return ret; + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data, + mode, event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_uninstall_packages(pkgmgr_client *pc, + const char **pkgids, int n_pkgs, pkgmgr_handler event_cb, + void *data) { + return pkgmgr_client_usr_uninstall_packages(pc, pkgids, n_pkgs, + event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_uninstall_packages(pkgmgr_client *pc, + const char **pkgids, int n_pkgs, pkgmgr_handler event_cb, + void *data, uid_t uid) { + if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb, + void *data) { + return pkgmgr_client_usr_uninstall(pc, pkg_type, pkgid, mode, event_cb, + data, getuid()); +} + +API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb, + void *data, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_listen_res_status(pkgmgr_client *pc, + pkgmgr_res_handler event_cb, void *data) { + Connector* con = static_cast<Connector*>(pc); + + con->GetSignalReceiver()->AddEventHandler("", event_cb, data); + return PKGMGR_R_OK; +} + +API int pkgmgr_client_usr_mount_install_packages(pkgmgr_client *pc, + const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, + void *data, uid_t uid) { + if (pc == nullptr || pkg_paths == nullptr || n_pkgs < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> pkgs; + for (int i = 0; i < n_pkgs; i++) + pkgs.push_back(pkg_paths[i]); + + int ret = proxy->MountInstallPkgs(uid, pkgs, con->GenerateRequestId(), + req_key); + if (ret != PKGMGR_R_OK) + return ret; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_mount_install_packages(pkgmgr_client *pc, + const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, + void *data) { + return pkgmgr_client_usr_mount_install_packages(pc, pkg_paths, n_pkgs, + event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, + const char *descriptor_path, const char *pkg_path, + const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkg_path == nullptr || pkg_type == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + int ret = proxy->MountInstall(uid, pkg_type, pkg_path, con->GetArgv(), + con->GenerateRequestId(), req_key); + if (ret != PKGMGR_R_OK) + return ret; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type, + const char *descriptor_path, const char *pkg_path, + const char *optional_data, pkgmgr_mode mode, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path, + pkg_path, optional_data, mode, event_cb, data, + getuid()); +} + +API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, pkgmgr_move_type move_type, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, + event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, pkgmgr_move_type move_type, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + if ((move_type < PM_MOVE_TO_INTERNAL) || + (move_type > PM_MOVE_TO_EXTENDED)) + return PKGMGR_R_EINVAL; + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc, + pkg_update_info_t *update_info, uid_t uid) { + if (pc == nullptr || update_info == nullptr || update_info->pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->RegisterPkgUpdateInfo(uid, update_info->pkgid, + update_info->pkgid, update_info->type); +} + +API int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc, + pkg_update_info_t *update_info) { + return pkgmgr_client_usr_register_pkg_update_info(pc, update_info, + getuid()); +} + +API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc, + const char *pkgid, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->UnregisterPkgUpdateInfo(uid, pkgid); +} + +API int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc, + const char *pkgid) { + return pkgmgr_client_usr_unregister_pkg_update_info(pc, pkgid, getuid()); +} + +API int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc, + uid_t uid) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->UnregisterAllPkgUpdateInfo(uid); +} + +API int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc) { + return pkgmgr_client_usr_unregister_all_pkg_update_info(pc, getuid()); +} + +API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + return proxy->EnablePkgs(uid, { pkgid }, req_key); +} + +API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid) { + return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, getuid()); +} + +API int pkgmgr_client_usr_activate_packages(pkgmgr_client *pc, + const char *pkg_type, const char **pkgids, int n_pkgs, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_activate_packages(pkgmgr_client *pc, + const char *pkg_type, const char **pkgids, int n_pkgs, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_activate_packages(pc, pkg_type, + pkgids, n_pkgs, event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + return proxy->DisablePkgs(uid, { pkgid }, req_key); +} + +API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid) { + return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, getuid()); +} + +API int pkgmgr_client_usr_deactivate_packages(pkgmgr_client *pc, + const char *pkg_type, const char **pkgids, int n_pkgs, + pkgmgr_handler event_cb, void *data, uid_t uid) { + if (pc == nullptr || pkgids == nullptr || n_pkgs < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_deactivate_packages(pkgmgr_client *pc, + const char *pkg_type, const char **pkgids, int n_pkgs, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_deactivate_packages(pc, pkg_type, + pkgids, n_pkgs, event_cb, data, getuid()); +} + +API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb, void *data) { + return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, + data, getuid()); +} + +API int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids, + int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appids == nullptr || n_apps < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids, + int n_apps, pkgmgr_app_handler app_event_cb, void *data) { + return pkgmgr_client_usr_activate_apps(pc, appids, n_apps, + app_event_cb, data, getuid()); +} + +API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, + const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb, void *data) { + return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, data, + getuid()); +} + +API int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc, + const char **appids, int n_apps, + pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appids == nullptr || n_apps < 1) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string req_key; + std::vector<std::string> 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids, + int n_apps, pkgmgr_app_handler app_event_cb, void *data) { + return pkgmgr_client_usr_deactivate_apps(pc, appids, n_apps, + app_event_cb, data, getuid()); +} + +API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc, + const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, app_event_cb, data); +} + +API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, + const char *pkg_type, const char *pkgid, pkgmgr_mode mode, + uid_t uid) { + if (pc == nullptr || pkgid == nullptr || uid == GLOBAL_USER) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->ClearData(uid, pkgid); +} + +API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, pkgmgr_mode mode) { + return pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, mode, + getuid()); +} + +API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb, + void *data) { + if (pc == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + return con->GetSignalReceiver()->AddEventHandler("", event_cb, data); +} + +API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, + pkgmgr_app_handler app_event_cb, void *data) { + if (pc == nullptr || app_event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + return con->GetSignalReceiver()->AddEventHandler("", app_event_cb, data); +} + +API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, const char *key, const char *val) { + /* client cannot broadcast signal */ + return PKGMGR_R_OK; +} + +/* TODO: deprecate(or remove) */ +API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, + int service_mode, pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, const char *custom_info, + pkgmgr_handler event_cb, void *data) { + return pkgmgr_client_usr_request_service(service_type, service_mode, + pc, pkg_type, pkgid, getuid(), custom_info, event_cb, + data); +} + +API int pkgmgr_client_usr_request_service( + pkgmgr_request_service_type service_type, int service_mode, + pkgmgr_client *pc, const char *pkg_type, const char *pkgid, + uid_t uid, const char *custom_info, pkgmgr_handler event_cb, + void *data) { + //TODO + return 0; +} + +API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) { + //TODO + return 0; +} + +API int pkgmgr_client_clear_cache_dir(const char *pkgid) { + return pkgmgr_client_usr_clear_cache_dir(pkgid, getuid()); +} + +API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid) { + return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid); +} + +API int pkgmgr_client_clear_all_cache_dir() { + return pkgmgr_client_usr_clear_cache_dir( + PKG_CLEAR_ALL_CACHE, getuid()); +} + +API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid, + pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, + void *data) { + return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data, + getuid()); +} + +/* TODO: deprecate(or remove) */ +API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, + pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, + void *data, uid_t uid) { + if (pc == nullptr || pkgid == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) + get_type = PM_GET_TOTAL_PKG_SIZE_INFO; + else + get_type = PM_GET_PKG_SIZE_INFO; + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, data); +} + +API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc, + const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, + void *user_data, uid_t uid) { + if (pc == nullptr || pkgid == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + int get_type; + if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) + get_type = PM_GET_TOTAL_PKG_SIZE_INFO; + else + get_type = PM_GET_PKG_SIZE_INFO; + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, user_data); +} + +API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, + const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, + void *user_data) { + return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, + user_data, getuid()); +} + +API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, + pkgmgr_total_pkg_size_info_receive_cb event_cb, + void *user_data, uid_t uid) { + return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, + (pkgmgr_pkg_size_info_receive_cb)event_cb, + user_data, uid); +} + +API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, + pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data) { + return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, + (pkgmgr_pkg_size_info_receive_cb)event_cb, + user_data, getuid()); +} + +API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, + const char *resp_data, char **req_data, char **license_url) { + if (pc == nullptr || resp_data == nullptr || req_data == nullptr || + license_url == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + std::string data; + std::string url; + int ret = proxy->GenerateLicenseRequest(resp_data, 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; +} + +API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) { + if (pc == nullptr || resp_data == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->RegisterLicense(resp_data); +} + +API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, + const char *drm_file_path, const char *decrypted_file_path) { + if (pc == nullptr || drm_file_path == nullptr || + decrypted_file_path == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->DecryptPackage(drm_file_path, decrypted_file_path); +} + +API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid) { + return pkgmgr_client_usr_enable_splash_screen(pc, appid, getuid()); +} + +API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, + const char *appid, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("Invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->EnableAppSplashScreen(uid, appid); +} + +API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc, + const char *appid) { + return pkgmgr_client_usr_disable_splash_screen(pc, appid, + getuid()); +} + +API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, + const char *appid, uid_t uid) { + if (pc == nullptr || appid == nullptr) { + _E("Invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->DisableAppSplashScreen(uid, appid); +} + +API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode, uid_t uid) { + if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0 || mode <= 0) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->SetRestrictionMode(uid, pkgid, mode); +} + +API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode) { + return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, + getuid()); +} + +API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode, uid_t uid) { + if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0 || mode <= 0) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->UnsetRestrictionMode(uid, pkgid, mode); +} + +API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode) { + return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, + getuid()); +} + +API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int *mode, uid_t uid) { + if (pc == nullptr || pkgid == nullptr || strlen(pkgid) == 0) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->GetRestrictionMode(uid, pkgid, *mode); +} + +API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int *mode) { + return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, + getuid()); +} + +API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode, + uid_t uid) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->SetRestrictionMode(uid, "", mode); +} + +API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode) { + return pkgmgr_client_usr_set_restriction_mode(pc, mode, getuid()); +} + +API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode, + uid_t uid) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->UnsetRestrictionMode(uid, "", mode); +} + +API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode) { + return pkgmgr_client_usr_unset_restriction_mode(pc, mode, getuid()); +} + +API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc, + int *mode, uid_t uid) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->GetRestrictionMode(uid, "", *mode); +} + +API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode) { + return pkgmgr_client_usr_get_restriction_mode(pc, mode, getuid()); +} + +API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path) { + //TODO + return nullptr; +} + +API int pkgmgr_client_free_pkginfo(pkgmgr_info *info) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_client_usr_set_app_label(pkgmgr_client *pc, char *appid, + char *label, uid_t uid) { + if (pc == nullptr || appid == nullptr || label == nullptr) { + _E("Invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->SetAppLabel(uid, appid, label); +} + +API int pkgmgr_client_set_app_label(pkgmgr_client *pc, char *appid, char *label) { + return pkgmgr_client_usr_set_app_label(pc, appid, label, getuid()); +} + +API int pkgmgr_client_usr_set_app_icon(pkgmgr_client *pc, char *appid, + char *icon_path, uid_t uid) { + if (pc == nullptr || appid == nullptr || icon_path == nullptr) { + _E("Invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->SetAppIcon(uid, appid, icon_path); +} + +API int pkgmgr_client_set_app_icon(pkgmgr_client *pc, char *appid, char *icon_path) { + return pkgmgr_client_usr_set_app_icon(pc, appid, icon_path, getuid()); +} + +API int pkgmgr_client_set_debug_mode(pkgmgr_client *pc, bool debug_mode) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + if (debug_mode) + con->SetDebugMode(); + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_set_skip_optimization(pkgmgr_client *pc, bool skip_optimization) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + if (skip_optimization) + con->SetSkipOptimization(); + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_usr_migrate_external_image(pkgmgr_client *pc, + const char *pkgid, uid_t uid) { + if (pc == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->MigrateExternalImage(uid, pkgid); +} + +API int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc, + const char *src_path, const char *dest_path) { + if (pc == nullptr || src_path == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + con->GetResCopyPath().push_back( + pp::ResPath(src_path, dest_path ? dest_path: "")); + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_res_copy(pkgmgr_client *pc, + pkgmgr_res_handler event_cb, void *user_data) { + if (pc == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, + user_data); +} + +API int pkgmgr_client_add_res_create_dir_path(pkgmgr_client *pc, + const char *dir_path) { + if (pc == nullptr || dir_path == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + con->GetResCreateDir().push_back(dir_path); + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_res_create_dir(pkgmgr_client *pc, + pkgmgr_res_handler event_cb, void *user_data) { + if (pc == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, + user_data); +} + +API int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc, + const char *res_path) { + if (pc == nullptr || res_path == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + con->GetResRemovePath().push_back(res_path); + + return PKGMGR_R_OK; +} + +API int pkgmgr_client_res_remove(pkgmgr_client *pc, + pkgmgr_res_handler event_cb, void *user_data) { + if (pc == nullptr || event_cb == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + 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; + + return con->GetSignalReceiver()->AddEventHandler(req_key, event_cb, + user_data); +} + +API int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid) { + return pkgmgr_client_res_usr_uninstall(pc, pkgid, getuid()); +} + +API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, + uid_t uid) { + if (pc == nullptr || pkgid == nullptr) { + _E("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + auto* con = static_cast<Connector*>(pc); + auto* proxy = con->GetAdminProxy(); + if (proxy == nullptr) + return PKGMGR_R_EIO; + + return proxy->ResUninstall(uid, pkgid); +} + +API pkgmgr_res_event_info *pkgmgr_res_event_info_new() { + //TODO + return nullptr; +} + +API int pkgmgr_res_event_info_free(pkgmgr_res_event_info *info) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_set_error_code(pkgmgr_res_event_info *handle, int error_code) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_get_error_code(pkgmgr_res_event_info *handle, int *error_code) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_add_path_state(pkgmgr_res_event_info *handle, + const char *path, pkgmgr_res_event_path_state state) { + //TODO + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_foreach_path(pkgmgr_res_event_info *handle, + pkgmgr_res_event_path_cb callback, void *user_data) { + //TODO + return PKGMGR_R_OK; +} diff --git a/client/src/connection_event_listener.hh b/client/src/connection_event_listener.hh new file mode 100644 index 0000000..35a8a5d --- /dev/null +++ b/client/src/connection_event_listener.hh @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_ +#define CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_ + +#include <memory> +#include <string> + +#include "PkgMgrProxy.h" + +namespace pkgmgr { +namespace client { + +enum class ConnectionState { + NotRequested, + Connected, + Disconnected, + Rejected, +}; + +template<class T> +class ConnectionEventListener : public T::IEventListener { + public: + void OnConnected() override { + state_ = ConnectionState::Connected; + } + + void OnDisconnected() override { + state_ = ConnectionState::Disconnected; + } + + void OnRejected() override { + state_ = ConnectionState::Rejected; + } + + ConnectionState GetState() const { + return state_; + } + + private: + ConnectionState state_ = ConnectionState::NotRequested; +}; + +} // namespace client +} // namespace pkgmgr + +#endif // CLIENT_SRC_CONNECTION_EVENT_LISTENER_H_
\ No newline at end of file diff --git a/client/src/connector.cc b/client/src/connector.cc new file mode 100644 index 0000000..73ff285 --- /dev/null +++ b/client/src/connector.cc @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "connector.hh" + +#include <time.h> +#include <unistd.h> + +namespace { + +constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.pkgmgr"; + +} + +namespace pkgmgr { +namespace client { + +Connector::~Connector() = default; + +std::string Connector::GenerateRequestId() const { + struct timeval tv; + gettimeofday(&tv, NULL); + long curtime = tv.tv_sec * 1000000 + tv.tv_usec; + + return std::to_string(getpid()) + "_" + std::to_string(curtime); +} + +void Connector::SetTep(std::string tep_path, bool tep_move) { + argv_.push_back("-e"); + argv_.push_back(std::move(tep_path)); + argv_.push_back("-M"); + argv_.push_back(tep_move ? "tep_move" : "tep_copy"); +} + +void Connector::SetDebugMode() { + argv_.push_back("-G"); +} + +void Connector::SetSkipOptimization() { + argv_.push_back("-S"); +} + +const std::vector<std::string>& Connector::GetArgv() const { + return argv_; +} + +pkg_proxy::PkgMgrAdmin* Connector::GetAdminProxy() { + if (!ConnectForAdmin()) + return nullptr; + + return admin_proxy_.get(); +} + +pkg_proxy::PkgMgr* Connector::GetInfoProxy() { + if (!ConnectForInfo()) + return nullptr; + + return info_proxy_.get(); +} + +pkg_proxy::PkgMgrForClearCache* Connector::GetCacheProxy() { + if (!ConnectForCache()) + return nullptr; + + return cache_proxy_.get(); +} + +bool Connector::ConnectForAdmin() { + if (!admin_proxy_) { + admin_proxy_.reset(new pkg_proxy::PkgMgrAdmin(&conn_admin_listener_, + SERVER_PROC_NAME)); + } + + if (conn_admin_listener_.GetState() == ConnectionState::Connected) + return true; + + try { + admin_proxy_->Connect(true); + } catch (const pkg_proxy::Exception& e) { + return false; + } + + return true; +} + +bool Connector::ConnectForInfo() { + if (!info_proxy_) { + info_proxy_.reset(new pkg_proxy::PkgMgr(&conn_info_listener_, + SERVER_PROC_NAME)); + } + + if (conn_info_listener_.GetState() == ConnectionState::Connected) + return true; + + try { + info_proxy_->Connect(true); + } catch (const pkg_proxy::Exception& e) { + return false; + } + + return true; +} + +bool Connector::ConnectForCache() { + if (!cache_proxy_) { + cache_proxy_.reset(new pkg_proxy::PkgMgrForClearCache(&conn_cache_listener_, + SERVER_PROC_NAME)); + } + + if (conn_cache_listener_.GetState() == ConnectionState::Connected) + return true; + + try { + cache_proxy_->Connect(true); + } catch (const pkg_proxy::Exception& e) { + return false; + } + + return true; +} + +const std::unique_ptr<SignalReceiver>& Connector::GetSignalReceiver() { + if (!signal_receiver_) + signal_receiver_.reset(new SignalReceiver()); + + return signal_receiver_; +} + +std::vector<std::string>& Connector::GetResRemovePath() { + return res_remove_path_; +} + +std::vector<std::string>& Connector::GetResCreateDir() { + return res_create_dir_; +} + +std::vector<pp::ResPath>& Connector::GetResCopyPath() { + return res_copy_path_; +} + +} // namespace client +} // namespace pkgmgr diff --git a/client/src/connector.hh b/client/src/connector.hh new file mode 100644 index 0000000..51a4706 --- /dev/null +++ b/client/src/connector.hh @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef CLIENT_SRC_CONNECTOR_H_ +#define CLIENT_SRC_CONNECTOR_H_ + +#include <memory> +#include <string> +#include <vector> + +#include "PkgMgrProxy.h" + +#include "connection_event_listener.hh" +#include "signal_receiver.hh" + +namespace pkgmgr { +namespace client { + +namespace pkg_proxy = rpc_port::PkgMgrProxy::proxy; +namespace pp = rpc_port::PkgMgrProxy; + +class Connector { + public: + Connector() = default; + virtual ~Connector(); + + virtual pkg_proxy::PkgMgrAdmin* GetAdminProxy(); + virtual pkg_proxy::PkgMgr* GetInfoProxy(); + virtual pkg_proxy::PkgMgrForClearCache* GetCacheProxy(); + virtual const std::unique_ptr<SignalReceiver>& GetSignalReceiver(); + std::string GenerateRequestId() const; + void SetTep(std::string tep_path, bool tep_move); + void SetDebugMode(); + void SetSkipOptimization(); + const std::vector<std::string>& GetArgv() const; + std::vector<std::string>& GetResRemovePath(); + std::vector<std::string>& GetResCreateDir(); + std::vector<pp::ResPath>& GetResCopyPath(); + + private: + bool ConnectForAdmin(); + bool ConnectForInfo(); + bool ConnectForCache(); + + private: + std::unique_ptr<pkg_proxy::PkgMgr> info_proxy_; + std::unique_ptr<pkg_proxy::PkgMgrForClearCache> cache_proxy_; + std::unique_ptr<pkg_proxy::PkgMgrAdmin> admin_proxy_; + std::vector<std::string> argv_; + ConnectionEventListener<pkg_proxy::PkgMgrAdmin> conn_admin_listener_; + ConnectionEventListener<pkg_proxy::PkgMgr> conn_info_listener_; + ConnectionEventListener<pkg_proxy::PkgMgrForClearCache> conn_cache_listener_; + std::unique_ptr<SignalReceiver> signal_receiver_; + std::vector<std::string> res_remove_path_; + std::vector<std::string> res_create_dir_; + std::vector<pp::ResPath> res_copy_path_; +}; + +} // namespace client +} // namespace pkgmgr + +#endif // CLIENT_SRC_CONNECTOR_H_
\ No newline at end of file diff --git a/client/src/log.hh b/client/src/log.hh new file mode 100644 index 0000000..5668dd6 --- /dev/null +++ b/client/src/log.hh @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef SRC_LOG_H_ +#define SRC_LOG_H_ + +#include <dlog.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif /* LOG_TAG */ +#define LOG_TAG "PKGMGR_CLIENT" + +#undef _E +#define _E LOGE + +#undef _W +#define _W LOGW + +#undef _I +#define _I LOGI + +#undef _D +#define _D LOGD + +#endif // SRC_LOG_H_
\ No newline at end of file diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c deleted file mode 100644 index 650b2fe..0000000 --- a/client/src/pkgmgr.c +++ /dev/null @@ -1,3163 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, - * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <dlfcn.h> -#include <dirent.h> -#include <fcntl.h> -#include <sys/wait.h> -#include <sys/time.h> -#include <unzip.h> -#include <pthread.h> - -#include <glib.h> - -#include <pkgmgr-info.h> -#include <iniparser.h> -/* For multi-user support */ -#include <tzplatform_config.h> - -#include "package-manager.h" -#include "package-manager-types.h" -#include "pkgmgr_client_debug.h" -#include "pkgmgr_client_internal.h" - -/* API export macro */ -#ifndef API -#define API __attribute__ ((visibility("default"))) -#endif - -#define BINSH_NAME "/bin/sh" -#define BINSH_SIZE 7 - -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define REGULAR_USER 5000 - -static GList *jobs_to_free; -static pthread_mutex_t __mutex = PTHREAD_MUTEX_INITIALIZER; - -static inline uid_t _getuid(void) -{ - uid_t uid = getuid(); - - if (uid < REGULAR_USER) - return GLOBAL_USER; - else - return uid; -} - -static int _get_internal_request_id() -{ - static int internal_req_id = 1; - - return internal_req_id++; -} - -static char *_generate_request_id(void) -{ - struct timeval tv; - long curtime; - char buf[BUFMAX]; - - gettimeofday(&tv, NULL); - curtime = tv.tv_sec * 1000000 + tv.tv_usec; - - snprintf(buf, sizeof(buf), "%d_%ld", getpid(), curtime); - - return strdup(buf); -} - -static struct cb_info *__create_event_cb_info(struct pkgmgr_client_t *client, - pkgmgr_handler event_cb, void *data, const char *req_key) -{ - struct cb_info *cb_info; - - cb_info = calloc(1, sizeof(struct cb_info)); - if (cb_info == NULL) { - ERR("out of memory"); - return NULL; - } - cb_info->client = client; - cb_info->event_cb = event_cb; - cb_info->data = data; - cb_info->req_id = _get_internal_request_id(); - if (req_key != NULL) { - cb_info->req_key = strdup(req_key); - if (cb_info->req_key == NULL) { - ERR("out of memory"); - free(cb_info); - return NULL; - } - } - - return cb_info; -} - -static struct cb_info *__create_app_event_cb_info( - struct pkgmgr_client_t *client, pkgmgr_app_handler app_event_cb, - void *data, const char *req_key) -{ - struct cb_info *cb_info; - - cb_info = calloc(1, sizeof(struct cb_info)); - if (cb_info == NULL) { - ERR("out of memory"); - return NULL; - } - cb_info->client = client; - cb_info->app_event_cb = app_event_cb; - cb_info->data = data; - cb_info->req_id = _get_internal_request_id(); - if (req_key != NULL) { - cb_info->req_key = strdup(req_key); - if (cb_info->req_key == NULL) { - ERR("out of memory"); - free(cb_info); - return NULL; - } - } - - return cb_info; -} - -static struct cb_info *__create_res_event_cb_info( - struct pkgmgr_client_t *client, - pkgmgr_res_handler res_event_cb, - void *data, const char *req_key) -{ - struct cb_info *cb_info; - - cb_info = calloc(1, sizeof(struct cb_info)); - if (cb_info == NULL) { - ERR("out of memory"); - return NULL; - } - - cb_info->client = client; - cb_info->res_event_cb = res_event_cb; - cb_info->data = data; - cb_info->req_id = _get_internal_request_id(); - if (req_key == NULL) - return cb_info; - - cb_info->req_key = strdup(req_key); - if (cb_info->req_key == NULL) { - ERR("out of memory"); - free(cb_info); - return NULL; - } - - return cb_info; -} - -static struct cb_info *__create_size_info_cb_info( - struct pkgmgr_client_t *client, - pkgmgr_pkg_size_info_receive_cb size_info_cb, - void *data, const char *req_key) -{ - struct cb_info *cb_info; - - cb_info = calloc(1, sizeof(struct cb_info)); - if (cb_info == NULL) { - ERR("out of memory"); - return NULL; - } - cb_info->client = client; - cb_info->size_info_cb = size_info_cb; - cb_info->data = data; - cb_info->req_id = _get_internal_request_id(); - if (req_key != NULL) { - cb_info->req_key = strdup(req_key); - if (cb_info->req_key == NULL) { - ERR("out of memory"); - free(cb_info); - return NULL; - } - } - - return cb_info; -} - -static int __jobs_to_free_add(gpointer data) -{ - pthread_mutex_lock(&__mutex); - if (g_list_find(jobs_to_free, data)) { - pthread_mutex_unlock(&__mutex); - return -1; - } - - jobs_to_free = g_list_append(jobs_to_free, data); - pthread_mutex_unlock(&__mutex); - return 0; -} - -static void __jobs_to_free_remove(gpointer data) -{ - pthread_mutex_lock(&__mutex); - jobs_to_free = g_list_remove(jobs_to_free, data); - pthread_mutex_unlock(&__mutex); -} - -static void __do_free_cb_info(gpointer data) -{ - struct cb_info *cb_info = (struct cb_info *)data; - - g_list_free(cb_info->sid_list); - free(cb_info->req_key); - free(cb_info); -} - -static void __free_cb_info_cb(gpointer data) -{ - g_idle_remove_by_data(data); - __do_free_cb_info(data); -} - -__attribute__((destructor)) static void __free_cb_info_at_destructor(void) -{ - pthread_mutex_lock(&__mutex); - g_list_free_full(jobs_to_free, __free_cb_info_cb); - pthread_mutex_unlock(&__mutex); -} - -static gboolean __free_cb_info_at_idle(gpointer data) -{ - __jobs_to_free_remove(data); - __do_free_cb_info(data); - - return G_SOURCE_REMOVE; -} - -static void __free_cb_info(struct cb_info *cb_info) -{ - if (__jobs_to_free_add(cb_info) < 0) - return; - - g_idle_add(__free_cb_info_at_idle, cb_info); -} - -static int __get_size_process(pkgmgr_client *pc, const char *pkgid, uid_t uid, - pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, - void *data) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - long long size_info = 0; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "getsize_sync", - g_variant_new("(usi)", uid, pkgid, get_type), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(ix)", &ret, &size_info); - if (ret != PKGMGR_R_OK) { - ERR("request result failed: %d", ret); - g_variant_unref(result); - return ret; - } - - if (size_info < 0) { - ERR("invalid size_info=(%lld)", size_info); - ret = -1; - } else { - ret = (int)size_info; - DBG("size_info(%lld), return size(%d)", size_info, ret); - } - - g_variant_unref(result); - - return ret; -} - -static int __move_pkg_process(pkgmgr_client *pc, const char *pkgid, - const char *pkg_type, uid_t uid, pkgmgr_move_type move_type, - pkgmgr_handler event_cb, void *data) -{ - int ret; - - ret = pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, event_cb, data, uid); - if (ret < 0) { - ERR("move request failed"); - return ret; - } - - return ret; -} - -static int __check_app_process(pkgmgr_request_service_type service_type, - pkgmgr_client *pc, const char *pkgid, uid_t uid, void *data) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - pkgmgrinfo_pkginfo_h handle; - int pid = -1; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - retvm_if(client->pc_type != PC_REQUEST, PKGMGR_R_EINVAL, "client->pc_type is not PC_REQUEST\n"); - - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - if (ret != PMINFO_R_OK) { - ERR("pkgmgrinfo_pkginfo_get_pkginfo failed"); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return PKGMGR_R_ERROR; - } - - if (service_type == PM_REQUEST_KILL_APP) { - ret = pkgmgr_client_connection_send_request(client, "kill", - g_variant_new("(us)", uid, pkgid), &result); - } else if (service_type == PM_REQUEST_CHECK_APP) { - ret = pkgmgr_client_connection_send_request(client, "check", - g_variant_new("(us)", uid, pkgid), &result); - } else { - ERR("unexpected service type: %d", service_type); - ret = PKGMGR_R_ERROR; - } - - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return ret; - } - - g_variant_get(result, "(ii)", &ret, &pid); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) { - ERR("request failed, ret=%d", ret); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return ret; - } - - *(int *)data = pid; - - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - - return ret; - -} - -API pkgmgr_client *pkgmgr_client_new(pkgmgr_client_type pc_type) -{ - struct pkgmgr_client_t *client; - - if (pc_type == PC_BROADCAST) { - ERR("broadcast type is not supported"); - return NULL; - } - - if (pc_type != PC_REQUEST && pc_type != PC_LISTENING) { - ERR("invalid parameter"); - return NULL; - } - - client = calloc(1, sizeof(struct pkgmgr_client_t)); - if (client == NULL) { - ERR("out of memory"); - return NULL; - } - - client->pc_type = pc_type; - client->status_type = PKGMGR_CLIENT_STATUS_ALL; - - if (pkgmgr_client_connection_connect(client) != PKGMGR_R_OK) { - free(client); - return NULL; - } - - return (pkgmgr_client *)client; -} - -API int pkgmgr_client_free(pkgmgr_client *pc) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid argument"); - return PKGMGR_R_EINVAL; - } - - pkgmgr_client_remove_listen_status(client); - pkgmgr_client_connection_disconnect(client); - if (client->tep_path) - free(client->tep_path); - if (client->res_copy_builder) - g_variant_builder_unref(client->res_copy_builder); - if (client->res_remove_builder) - g_variant_builder_unref(client->res_remove_builder); - if (client->res_create_dir_builder) - g_variant_builder_unref(client->res_create_dir_builder); - free(client); - - return PKGMGR_R_OK; -} - -struct manifest_and_type type_map[] = { - { "res/wgt/config.xml", "wgt" }, - { "config.xml", "wgt" }, - { "tizen-manifest.xml", "tpk" }, - { NULL, NULL } -}; - -static char *__get_type_from_path(const char *pkg_path) -{ - const char *type = NULL; - unzFile uf; - int i; - - uf = unzOpen(pkg_path); - if (uf == NULL) { - ERR("failed to open zip file %s", pkg_path); - return NULL; - } - - for (i = 0; type_map[i].manifest != NULL; i++) { - if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) { - DBG("pkgtype of %s: [%s]", pkg_path, type_map[i].type); - type = type_map[i].type; - break; - } - } - unzClose(uf); - - return type ? strdup(type) : NULL; -} - -API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, const char *tep_path, - bool tep_move) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *) pc; - - if (pc == NULL || tep_path == NULL) { - ERR("invalied parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->tep_path) - free(client->tep_path); - - client->tep_path = strdup(tep_path); - client->tep_move = tep_move; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_usr_install_packages(pkgmgr_client *pc, - const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, - void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *pkgs_builder; - GVariant *pkgs; - GVariantBuilder *args_builder; - GVariant *args; - int ret; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - char *request_id = NULL; - - if (pc == NULL || pkg_paths == NULL || n_pkgs < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - for (i = 0; i < n_pkgs; i++) { - if (access(pkg_paths[i], F_OK) != 0) { - ERR("failed to access: %s", pkg_paths[i]); - return PKGMGR_R_EINVAL; - } - } - - pkgs_builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_pkgs; i++) - g_variant_builder_add(pkgs_builder, "s", pkg_paths[i]); - pkgs = g_variant_new("as", pkgs_builder); - g_variant_builder_unref(pkgs_builder); - - args_builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - if (client->debug_mode) - g_variant_builder_add(args_builder, "s", "-G"); - if (client->skip_optimization) - g_variant_builder_add(args_builder, "s", "-S"); - args = g_variant_new("as", args_builder); - g_variant_builder_unref(args_builder); - - request_id = _generate_request_id(); - ret = pkgmgr_client_connection_send_request(client, "install_pkgs", - g_variant_new("(u@as@ass)", uid, pkgs, args, - request_id), - &result); - free(request_id); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_install_packages(pkgmgr_client *pc, - const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, - void *data) -{ - return pkgmgr_client_usr_install_packages(pc, pkg_paths, n_pkgs, - event_cb, data, _getuid()); -} - -API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, - const char *descriptor_path, const char *pkg_path, - const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - GVariantBuilder *builder = NULL; - GVariant *args = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - char *request_id = NULL; - - if (pc == NULL || pkg_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - if (access(pkg_path, F_OK) != 0) { - ERR("failed to access: %s", pkg_path); - return PKGMGR_R_EINVAL; - } - - if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) { - ERR("failed to access: %s", client->tep_path); - return PKGMGR_R_EINVAL; - } - - /* build arguments */ - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - if (client->tep_path) { - g_variant_builder_add(builder, "s", "-e"); - g_variant_builder_add(builder, "s", client->tep_path); - g_variant_builder_add(builder, "s", "-M"); - /* TODO: revise tep_move */ - g_variant_builder_add(builder, "s", - client->tep_move ? "tep_move" : "tep_copy"); - } - if (client->debug_mode) - g_variant_builder_add(builder, "s", "-G"); - if (client->skip_optimization) - g_variant_builder_add(builder, "s", "-S"); - - args = g_variant_new("as", builder); - g_variant_builder_unref(builder); - - request_id = _generate_request_id(); - ret = pkgmgr_client_connection_send_request(client, "install", - g_variant_new("(uss@ass)", uid, pkg_type ? pkg_type : "", - pkg_path, args, request_id), - &result); - free(request_id); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return cb_info->req_id; -} - -API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type, - const char *descriptor_path, const char *pkg_path, - const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_install(pc, pkg_type, descriptor_path, - pkg_path, optional_data, mode, event_cb, data, - _getuid()); -} - -API int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_data, - mode, event_cb, data, _getuid()); -} - -API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "reinstall", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_usr_mount_install_packages(pkgmgr_client *pc, - const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, - void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *pkgs_builder; - GVariant *pkgs; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - char *request_id = NULL; - - if (pc == NULL || pkg_paths == NULL || n_pkgs < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - for (i = 0; i < n_pkgs; i++) { - if (access(pkg_paths[i], F_OK) != 0) { - ERR("failed to access: %s", pkg_paths[i]); - return PKGMGR_R_EINVAL; - } - } - - pkgs_builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_pkgs; i++) - g_variant_builder_add(pkgs_builder, "s", pkg_paths[i]); - pkgs = g_variant_new("as", pkgs_builder); - g_variant_builder_unref(pkgs_builder); - - request_id = _generate_request_id(); - ret = pkgmgr_client_connection_send_request(client, - "mount_install_pkgs", - g_variant_new("(u@ass)", uid, pkgs, request_id), - &result); - free(request_id); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_mount_install_packages(pkgmgr_client *pc, - const char **pkg_paths, int n_pkgs, pkgmgr_handler event_cb, - void *data) -{ - return pkgmgr_client_usr_mount_install_packages(pc, pkg_paths, n_pkgs, - event_cb, data, _getuid()); -} - -API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, - const char *descriptor_path, const char *pkg_path, - const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - GVariantBuilder *builder = NULL; - GVariant *args = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - char *request_id = NULL; - - if (pc == NULL || pkg_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - if (access(pkg_path, F_OK) != 0) { - ERR("failed to access: %s", pkg_path); - return PKGMGR_R_EINVAL; - } - - if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) { - ERR("failed to access: %s", client->tep_path); - return PKGMGR_R_EINVAL; - } - - /* build arguments */ - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - if (client->tep_path) { - g_variant_builder_add(builder, "s", "-e"); - g_variant_builder_add(builder, "s", client->tep_path); - g_variant_builder_add(builder, "s", "-M"); - /* TODO: revise tep_move */ - g_variant_builder_add(builder, "s", - client->tep_move ? "tep_move" : "tep_copy"); - } - - args = g_variant_new("as", builder); - g_variant_builder_unref(builder); - - request_id = _generate_request_id(); - ret = pkgmgr_client_connection_send_request(client, "mount_install", - g_variant_new("(uss@ass)", uid, - pkg_type ? pkg_type : "", pkg_path, - args, request_id), - &result); - free(request_id); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type, - const char *descriptor_path, const char *pkg_path, - const char *optional_data, pkgmgr_mode mode, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_mount_install(pc, pkg_type, descriptor_path, - pkg_path, optional_data, mode, event_cb, data, - _getuid()); -} - -API int pkgmgr_client_usr_uninstall_packages(pkgmgr_client *pc, - const char **pkgids, int n_pkgs, pkgmgr_handler event_cb, - void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *pkgs_builder; - GVariant *pkgs; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - - if (pc == NULL || pkgids == NULL || n_pkgs < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - pkgs_builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_pkgs; i++) - g_variant_builder_add(pkgs_builder, "s", pkgids[i]); - pkgs = g_variant_new("as", pkgs_builder); - g_variant_builder_unref(pkgs_builder); - - ret = pkgmgr_client_connection_send_request(client, "uninstall_pkgs", - g_variant_new("(u@as)", uid, pkgs), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_uninstall_packages(pkgmgr_client *pc, - const char **pkgids, int n_pkgs, pkgmgr_handler event_cb, - void *data) -{ - return pkgmgr_client_usr_uninstall_packages(pc, pkgids, n_pkgs, - event_cb, data, _getuid()); -} - -API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb, - void *data) -{ - return pkgmgr_client_usr_uninstall(pc, pkg_type, pkgid, mode, event_cb, - data, _getuid()); -} - -API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, pkgmgr_mode mode, pkgmgr_handler event_cb, - void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "uninstall", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, pkgmgr_move_type move_type, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_move(pc, pkg_type, pkgid, move_type, - event_cb, data, _getuid()); -} -API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, pkgmgr_move_type move_type, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if ((move_type < PM_MOVE_TO_INTERNAL) || - (move_type > PM_MOVE_TO_EXTENDED)) - return PKGMGR_R_EINVAL; - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "move", - g_variant_new("(usi)", uid, pkgid, move_type), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc, - pkg_update_info_t *update_info, uid_t uid) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - GVariant *result; - - if (pc == NULL || update_info == NULL || update_info->pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "register_pkg_update_info", - g_variant_new("(ussi)", uid, update_info->pkgid, update_info->version, - update_info->type), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - g_variant_unref(result); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc, - pkg_update_info_t *update_info) -{ - return pkgmgr_client_usr_register_pkg_update_info(pc, update_info, - _getuid()); -} - -API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc, - const char *pkgid, uid_t uid) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - GVariant *result; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "unregister_pkg_update_info", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - g_variant_unref(result); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc, - const char *pkgid) -{ - return pkgmgr_client_usr_unregister_pkg_update_info(pc, pkgid, _getuid()); -} - -API int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc, - uid_t uid) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - GVariant *result; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "unregister_all_pkg_update_info", - g_variant_new("(u)", uid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - g_variant_unref(result); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc) -{ - return pkgmgr_client_usr_unregister_all_pkg_update_info(pc, _getuid()); -} - -API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - GVariantBuilder *builder; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - g_variant_builder_add(builder, "s", pkgid); - - ret = pkgmgr_client_connection_send_request(client, "enable_pkgs", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(is)", &ret, NULL); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_activate(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid) -{ - return pkgmgr_client_usr_activate(pc, pkg_type, pkgid, _getuid()); -} - -API int pkgmgr_client_usr_activate_packages(pkgmgr_client *pc, - const char *pkg_type, const char **pkgids, int n_pkgs, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *builder; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - - if (pc == NULL || pkgids == NULL || n_pkgs < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_pkgs; i++) - g_variant_builder_add(builder, "s", pkgids[i]); - - ret = pkgmgr_client_connection_send_request(client, "enable_pkgs", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_activate_packages(pkgmgr_client *pc, - const char *pkg_type, const char **pkgids, int n_pkgs, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_activate_packages(pc, pkg_type, - pkgids, n_pkgs, event_cb, data, _getuid()); -} - -API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, uid_t uid) -{ - GVariant *result; - GVariantBuilder *builder; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - g_variant_builder_add(builder, "s", pkgid); - - ret = pkgmgr_client_connection_send_request(client, "disable_pkgs", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(is)", &ret, NULL); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid) -{ - return pkgmgr_client_usr_deactivate(pc, pkg_type, pkgid, _getuid()); -} - -API int pkgmgr_client_usr_deactivate_packages(pkgmgr_client *pc, - const char *pkg_type, const char **pkgids, int n_pkgs, - pkgmgr_handler event_cb, void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *builder; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - - if (pc == NULL || pkgids == NULL || n_pkgs < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_pkgs; i++) - g_variant_builder_add(builder, "s", pkgids[i]); - - ret = pkgmgr_client_connection_send_request(client, "disable_pkgs", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_deactivate_packages(pkgmgr_client *pc, - const char *pkg_type, const char **pkgids, int n_pkgs, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_deactivate_packages(pc, pkg_type, - pkgids, n_pkgs, event_cb, data, _getuid()); -} - -API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid, - pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || appid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "enable_app", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, - req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, - pkgmgr_app_handler app_event_cb, void *data) -{ - return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, - data, _getuid()); -} - -API int pkgmgr_client_usr_activate_apps(pkgmgr_client *pc, const char **appids, - int n_apps, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *builder; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - - if (pc == NULL || appids == NULL || n_apps < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_apps; i++) - g_variant_builder_add(builder, "s", appids[i]); - - ret = pkgmgr_client_connection_send_request(client, "enable_apps", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_activate_apps(pkgmgr_client *pc, const char **appids, - int n_apps, pkgmgr_app_handler app_event_cb, void *data) -{ - return pkgmgr_client_usr_activate_apps(pc, appids, n_apps, - app_event_cb, data, _getuid()); -} - -API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, - const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || appid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "enable_global_app_for_uid", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, - req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, - pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || appid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "disable_app", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, - req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, - pkgmgr_app_handler app_event_cb, void *data) -{ - return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, data, - _getuid()); -} - -API int pkgmgr_client_usr_deactivate_apps(pkgmgr_client *pc, - const char **appids, int n_apps, - pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - GVariantBuilder *builder; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - int i; - - if (pc == NULL || appids == NULL || n_apps < 1) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < n_apps; i++) - g_variant_builder_add(builder, "s", appids[i]); - - ret = pkgmgr_client_connection_send_request(client, "disable_apps", - g_variant_new("(uas)", uid, builder), &result); - g_variant_builder_unref(builder); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ERROR; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_deactivate_apps(pkgmgr_client *pc, const char **appids, - int n_apps, pkgmgr_app_handler app_event_cb, void *data) -{ - return pkgmgr_client_usr_deactivate_apps(pc, appids, n_apps, - app_event_cb, data, _getuid()); -} - -API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc, - const char *appid, pkgmgr_app_handler app_event_cb, void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || appid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "disable_global_app_for_uid", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, - req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, - const char *pkg_type, const char *pkgid, pkgmgr_mode mode, - uid_t uid) -{ - GVariant *result; - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL || uid == GLOBAL_USER) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "cleardata", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, pkgmgr_mode mode) -{ - return pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, mode, - _getuid()); -} - -API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - client->status_type = status_type; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb, - void *data) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_LISTENING) { - ERR("client->pc_type is not PC_LISTENING"); - return PKGMGR_R_EINVAL; - } - - cb_info = __create_event_cb_info(client, event_cb, data, NULL); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - cb_info->status_type = client->status_type; - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, - pkgmgr_app_handler app_event_cb, void *data) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || app_event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_LISTENING) { - ERR("client->pc_type is not PC_LISTENING"); - return PKGMGR_R_EINVAL; - } - - cb_info = __create_app_event_cb_info(client, app_event_cb, data, NULL); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - cb_info->status_type = client->status_type; - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_listen_res_status(pkgmgr_client *pc, - pkgmgr_res_handler event_cb, void *data) -{ - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_LISTENING) { - ERR("client->pc_type is not PC_LISTENING"); - return PKGMGR_R_EINVAL; - } - - cb_info = __create_res_event_cb_info(client, event_cb, data, NULL); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - cb_info->status_type = client->status_type; - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - GList *tmp; - GList *next; - struct cb_info *cb_info; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - /* unset all callback */ - tmp = client->cb_info_list; - while (tmp != NULL) { - next = tmp->next; - cb_info = (struct cb_info *)tmp->data; - pkgmgr_client_connection_unset_callback(pc, cb_info); - client->cb_info_list = g_list_delete_link(client->cb_info_list, - tmp); - __free_cb_info(cb_info); - tmp = next; - } - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, const char *key, const char *val) -{ - /* client cannot broadcast signal */ - return PKGMGR_R_OK; -} - -/* TODO: deprecate(or remove) */ -API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, - int service_mode, pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, const char *custom_info, - pkgmgr_handler event_cb, void *data) -{ - return pkgmgr_client_usr_request_service(service_type, service_mode, - pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, - data); -} - -API int pkgmgr_client_usr_request_service( - pkgmgr_request_service_type service_type, int service_mode, - pkgmgr_client *pc, const char *pkg_type, const char *pkgid, - uid_t uid, const char *custom_info, pkgmgr_handler event_cb, - void *data) -{ - int ret = 0; - - /* Check for NULL value of service type */ - retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n"); - retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n"); - - switch (service_type) { - case PM_REQUEST_MOVE: - tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n"); - tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n"); - tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_EXTENDED), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n"); - - ret = __move_pkg_process(pc, pkgid, pkg_type, uid, (pkgmgr_move_type)service_mode, event_cb, data); - break; - - case PM_REQUEST_GET_SIZE: - tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n"); - tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n"); - tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n"); - - ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data); - break; - - case PM_REQUEST_KILL_APP: - case PM_REQUEST_CHECK_APP: - tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n"); - tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n"); - - ret = __check_app_process(service_type, pc, pkgid, uid, data); - if (ret < 0) - ERR("__check_app_process fail \n"); - else - ret = PKGMGR_R_OK; - - break; - - default: - ERR("Wrong Request\n"); - ret = -1; - break; - } - -catch: - - return ret; -} - -API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) -{ - GVariant *result; - int ret; - struct pkgmgr_client_t *client; - - if (pkgid == NULL || uid == GLOBAL_USER) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - client = pkgmgr_client_new(PC_REQUEST); - if (client == NULL) { - ERR("out of memory"); - return PKGMGR_R_ENOMEM; - } - - ret = pkgmgr_client_connection_send_request(client, "clearcache", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - pkgmgr_client_free(client); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - pkgmgr_client_free(client); - - return ret; -} - -API int pkgmgr_client_clear_cache_dir(const char *pkgid) -{ - return pkgmgr_client_usr_clear_cache_dir(pkgid, _getuid()); -} - -API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid) -{ - return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, uid); -} - -API int pkgmgr_client_clear_all_cache_dir(void) -{ - return pkgmgr_client_usr_clear_cache_dir( - PKG_CLEAR_ALL_CACHE, _getuid()); -} - -API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid, - pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, - void *data) -{ - return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data, - _getuid()); -} - -/* TODO: deprecate(or remove) */ -API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, - pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, - void *data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || pkgid == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - /* FIXME */ - if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) - get_type = PM_GET_TOTAL_PKG_SIZE_INFO; - else - get_type = PM_GET_PKG_SIZE_INFO; - - ret = pkgmgr_client_connection_send_request(client, "getsize", - g_variant_new("(usi)", uid, pkgid, get_type), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_event_cb_info(client, event_cb, data, req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc, - const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, - void *user_data, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - int get_type; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || pkgid == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) - get_type = PM_GET_TOTAL_PKG_SIZE_INFO; - else - get_type = PM_GET_PKG_SIZE_INFO; - - ret = pkgmgr_client_connection_send_request(client, "getsize", - g_variant_new("(usi)", uid, pkgid, get_type), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_size_info_cb_info(client, event_cb, user_data, - req_key); - if (cb_info == NULL) { - g_variant_unref(result); - return PKGMGR_R_ENOMEM; - } - g_variant_unref(result); - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, - const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, - void *user_data) -{ - return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, - user_data, _getuid()); -} - -API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, - pkgmgr_total_pkg_size_info_receive_cb event_cb, - void *user_data, uid_t uid) -{ /* total package size info */ - return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, - (pkgmgr_pkg_size_info_receive_cb)event_cb, - user_data, uid); -} - -API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, - pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data) -{ - return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, - (pkgmgr_pkg_size_info_receive_cb)event_cb, - user_data, _getuid()); -} - -API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, - const char *resp_data, char **req_data, char **license_url) -{ - GVariant *result; - int ret; - char *data; - char *url; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || resp_data == NULL || req_data == NULL || - license_url == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "generate_license_request", - g_variant_new("(s)", resp_data), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s&s)", &ret, &data, &url); - if (ret != PKGMGR_R_OK) { - ERR("generate_license_request failed: %d", ret); - g_variant_unref(result); - return ret; - } - - *req_data = strdup(data); - *license_url = strdup(url); - - g_variant_unref(result); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) -{ - GVariant *result; - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || resp_data == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "register_license", - g_variant_new("(s)", resp_data), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - ERR("register license failed: %d", ret); - - return ret; -} - -API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, - const char *drm_file_path, const char *decrypted_file_path) -{ - GVariant *result; - int ret; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || drm_file_path == NULL || - decrypted_file_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->pc_type != PC_REQUEST) { - ERR("client->pc_type is not PC_REQUEST"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, "decrypt_package", - g_variant_new("(ss)", drm_file_path, - decrypted_file_path), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - ERR("decrypt_package failed: %d", ret); - - return ret; -} - -API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid) -{ - return pkgmgr_client_usr_enable_splash_screen(pc, appid, _getuid()); -} - -API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, - const char *appid, uid_t uid) -{ - int ret; - GVariant *result; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || appid == NULL) { - ERR("Invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "enable_app_splash_screen", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - ERR("enable splash screen failed: %d", ret); - - return ret; -} - -API int pkgmgr_client_disable_splash_screen(pkgmgr_client *pc, - const char *appid) -{ - return pkgmgr_client_usr_disable_splash_screen(pc, appid, - _getuid()); -} - -API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, - const char *appid, uid_t uid) -{ - int ret; - GVariant *result; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || appid == NULL) { - ERR("Invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "disable_app_splash_screen", - g_variant_new("(us)", uid, appid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - ERR("disable splash screen failed: %d", ret); - - return ret; -} - -static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, - int mode, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "set_restriction_mode", - g_variant_new("(usi)", uid, pkgid, mode), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int mode, uid_t uid) -{ - return __set_pkg_restriction_mode(pc, pkgid, mode, uid); -} - -API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int mode) -{ - return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, - _getuid()); -} - -static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, - int mode, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "unset_restriction_mode", - g_variant_new("(usi)", uid, pkgid, mode), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; - -} - -API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int mode, uid_t uid) -{ - return __unset_pkg_restriction_mode(pc, pkgid, mode, uid); -} - -API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int mode) -{ - return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, - _getuid()); -} - -static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, - int *mode, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - gint m; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "get_restriction_mode", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(ii)", &m, &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - return ret; - - *mode = m; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int *mode, uid_t uid) -{ - return __get_pkg_restriction_mode(pc, pkgid, mode, uid); -} - -API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, - const char *pkgid, int *mode) -{ - return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, - _getuid()); -} - -API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode, - uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "set_restriction_mode", - g_variant_new("(usi)", uid, "", mode), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_set_restriction_mode(pkgmgr_client *pc, int mode) -{ - return pkgmgr_client_usr_set_restriction_mode(pc, mode, _getuid()); -} - -API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode, - uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "unset_restriction_mode", - g_variant_new("(usi)", uid, "", mode), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_unset_restriction_mode(pkgmgr_client *pc, int mode) -{ - return pkgmgr_client_usr_unset_restriction_mode(pc, mode, _getuid()); -} - -API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc, - int *mode, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - gint m; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "get_restriction_mode", - g_variant_new("(us)", uid, ""), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(ii)", &m, &ret); - g_variant_unref(result); - if (ret != PKGMGR_R_OK) - return ret; - - *mode = m; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode) -{ - return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid()); -} - -API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path) -{ - int ret; - pkg_plugin_set *plugin_set; - package_manager_pkg_detail_info_t *info; - char *pkg_type; - - if (pkg_path == NULL) { - ERR("invalid parameter"); - return NULL; - } - - pkg_type = __get_type_from_path(pkg_path); - if (pkg_type == NULL) { - ERR("cannot get pkg type"); - return NULL; - } - - plugin_set = _package_manager_load_library(pkg_type); - if (plugin_set == NULL) { - ERR("failed to load library for %s", pkg_type); - free(pkg_type); - return NULL; - } - - info = calloc(1, sizeof(package_manager_pkg_detail_info_t)); - if (info == NULL) { - ERR("out of memory"); - free(pkg_type); - return NULL; - } - - ret = plugin_set->get_pkg_detail_info_from_package(pkg_path, info); - if (ret) { - ERR("get_pkg_detail_info_from_package failed"); - free(info); - free(pkg_type); - return NULL; - } - - free(pkg_type); - - return (pkgmgr_info *)info; -} - -API int pkgmgr_client_free_pkginfo(pkgmgr_info *info) -{ - package_manager_pkg_detail_info_t *pkg_info = - (package_manager_pkg_detail_info_t *)info; - - if (info == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - g_list_free_full(pkg_info->privilege_list, free); - free(pkg_info->icon_buf); - free(pkg_info); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_usr_set_app_label(pkgmgr_client *pc, char *appid, - char *label, uid_t uid) -{ - GVariant *result; - int ret = -1; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || appid == NULL || label == NULL) { - ERR("Invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "set_app_label", - g_variant_new("(uss)", uid, appid, label), &result); - if (ret != PKGMGR_R_OK) { - ERR("Request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_set_app_label(pkgmgr_client *pc, char *appid, char *label) -{ - return pkgmgr_client_usr_set_app_label(pc, appid, label, _getuid()); -} - -API int pkgmgr_client_usr_set_app_icon(pkgmgr_client *pc, char *appid, - char *icon_path, uid_t uid) -{ - GVariant *result; - int ret = -1; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || appid == NULL || icon_path == NULL) { - ERR("Invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (access(icon_path, F_OK) != 0) { - ERR("failed to access: %s", icon_path); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "set_app_icon", - g_variant_new("(uss)", uid, appid, icon_path), &result); - if (ret != PKGMGR_R_OK) { - ERR("Request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_set_app_icon(pkgmgr_client *pc, char *appid, char *icon_path) -{ - return pkgmgr_client_usr_set_app_icon(pc, appid, icon_path, _getuid()); -} - -API int pkgmgr_client_set_debug_mode(pkgmgr_client *pc, bool debug_mode) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - client->debug_mode = debug_mode; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_set_skip_optimization(pkgmgr_client *pc, bool skip_optimization) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - client->skip_optimization = skip_optimization; - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_usr_migrate_external_image(pkgmgr_client *pc, - const char *pkgid, uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "migrate_external_image", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc, - const char *src_path, const char *dest_path) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || src_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->res_copy_builder == NULL) { - client->res_copy_builder = - g_variant_builder_new(G_VARIANT_TYPE("a(ss)")); - if (client->res_copy_builder == NULL) { - ERR("out of memory"); - return PKGMGR_R_ENOMEM; - } - } - - g_variant_builder_add(client->res_copy_builder, "(ss)", - src_path, dest_path ? dest_path : ""); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_res_copy(pkgmgr_client *pc, - pkgmgr_res_handler event_cb, void *user_data) -{ - GVariant *result; - int ret; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "res_copy", - g_variant_new("(a(ss))", - client->res_copy_builder), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_res_event_cb_info(client, - event_cb, user_data, req_key); - g_variant_unref(result); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_add_res_create_dir_path(pkgmgr_client *pc, - const char *dir_path) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || dir_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->res_create_dir_builder == NULL) { - client->res_create_dir_builder = - g_variant_builder_new(G_VARIANT_TYPE("as")); - if (client->res_create_dir_builder == NULL) { - ERR("out of memory"); - return PKGMGR_R_ENOMEM; - } - } - - g_variant_builder_add(client->res_create_dir_builder, "s", dir_path); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_res_create_dir(pkgmgr_client *pc, - pkgmgr_res_handler event_cb, void *user_data) -{ - GVariant *result; - int ret; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "res_create_dir", - g_variant_new("(as)", - client->res_create_dir_builder), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_res_event_cb_info(client, - event_cb, user_data, req_key); - g_variant_unref(result); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc, - const char *res_path) -{ - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || res_path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - if (client->res_remove_builder == NULL) { - client->res_remove_builder = - g_variant_builder_new(G_VARIANT_TYPE("as")); - if (client->res_remove_builder == NULL) { - ERR("out of memory"); - return PKGMGR_R_ENOMEM; - } - } - - g_variant_builder_add(client->res_remove_builder, "s", res_path); - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_res_remove(pkgmgr_client *pc, - pkgmgr_res_handler event_cb, void *user_data) -{ - GVariant *result; - int ret; - char *req_key = NULL; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - struct cb_info *cb_info; - - if (pc == NULL || event_cb == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "res_remove", - g_variant_new("(as)", - client->res_remove_builder), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i&s)", &ret, &req_key); - if (req_key == NULL) { - g_variant_unref(result); - return PKGMGR_R_ECOMM; - } - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - - cb_info = __create_res_event_cb_info(client, - event_cb, user_data, req_key); - g_variant_unref(result); - if (cb_info == NULL) - return PKGMGR_R_ENOMEM; - - ret = pkgmgr_client_connection_set_callback(client, cb_info); - if (ret != PKGMGR_R_OK) { - __free_cb_info(cb_info); - return ret; - } - client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - - return cb_info->req_id; -} - -API int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid) -{ - return pkgmgr_client_res_usr_uninstall(pc, pkgid, _getuid()); -} - -API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, - uid_t uid) -{ - GVariant *result; - int ret = PKGMGR_R_ECOMM; - struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - - if (pc == NULL || pkgid == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - ret = pkgmgr_client_connection_send_request(client, - "res_uninstall", - g_variant_new("(us)", uid, pkgid), &result); - if (ret != PKGMGR_R_OK) { - ERR("request failed: %d", ret); - return ret; - } - - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - - return ret; -} - -API pkgmgr_res_event_info *pkgmgr_res_event_info_new() -{ - pkgmgr_res_event_info_t *info; - - info = calloc(1, sizeof(pkgmgr_res_event_info_t)); - if (info == NULL) { - ERR("out of memory"); - return NULL; - } - - return (pkgmgr_res_event_info *)info; -} - -static void __free_path_states(gpointer data) -{ - res_event_path_state_t *path_state = (res_event_path_state_t *)data; - - if (path_state == NULL) - return; - if (path_state->path) - free(path_state->path); - free(path_state); -} - -API int pkgmgr_res_event_info_free(pkgmgr_res_event_info *info) -{ - pkgmgr_res_event_info_t *event_info = - (pkgmgr_res_event_info_t *)info; - - if (event_info == NULL) { - ERR("invalid argument"); - return PKGMGR_R_EINVAL; - } - - if (event_info->path_states) - g_list_free_full(event_info->path_states, __free_path_states); - free(event_info); - - return PKGMGR_R_OK; -} - -API int pkgmgr_res_event_info_set_error_code(pkgmgr_res_event_info *handle, int error_code) -{ - pkgmgr_res_event_info_t *info = handle; - if (info == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - info->error_code = error_code; - return PKGMGR_R_OK; -} - -API int pkgmgr_res_event_info_get_error_code(pkgmgr_res_event_info *handle, int *error_code) -{ - pkgmgr_res_event_info_t *info = handle; - if (info == NULL || error_code == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - *error_code = info->error_code; - return PKGMGR_R_OK; -} - -API int pkgmgr_res_event_info_add_path_state(pkgmgr_res_event_info *handle, - const char *path, pkgmgr_res_event_path_state state) -{ - pkgmgr_res_event_info_t *info = handle; - res_event_path_state_t *path_state; - - if (info == NULL || path == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - path_state = calloc(1, sizeof(res_event_path_state_t)); - if (path_state == NULL) { - ERR("out of memory"); - return PKGMGR_R_ENOMEM; - } - - path_state->path = strdup(path); - if (path_state->path == NULL) { - ERR("out of memory"); - free(path_state); - return PKGMGR_R_ENOMEM; - } - path_state->state = state; - - info->path_states = g_list_prepend(info->path_states , path_state); - return PKGMGR_R_OK; -} - -API int pkgmgr_res_event_info_foreach_path(pkgmgr_res_event_info *handle, - pkgmgr_res_event_path_cb callback, void *user_data) -{ - pkgmgr_res_event_info_t *info = handle; - GList *list; - res_event_path_state_t *path_state; - - if (info == NULL) { - ERR("invalid parameter"); - return PKGMGR_R_EINVAL; - } - - for (list = info->path_states; list != NULL; list = list->next) { - path_state = (res_event_path_state_t *)list->data; - if (callback(path_state->path, path_state->state, - user_data) < 0) - return PKGMGR_R_OK; - } - - return PKGMGR_R_OK; -} diff --git a/client/src/pkgmgr_client_connection.c b/client/src/pkgmgr_client_connection.c deleted file mode 100644 index 4600907..0000000 --- a/client/src/pkgmgr_client_connection.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <unistd.h> - -#include <glib.h> -#include <gio/gio.h> - -#include "package-manager.h" -#include "pkgmgr_client_debug.h" -#include "pkgmgr_client_internal.h" -#include "../../installer/pkgmgr_installer.h" -#include "../../installer/pkgmgr_installer_config.h" - -#define CONNECTION_RETRY_MAX 5 -#define CONNECTION_WAIT_USEC (1000000 / 2) /* 0.5 sec */ -#define CONNECTION_TIMEOUT_MSEC 5000 /* 5 sec */ -#define REGULAR_USER 5000 - -static int _is_system_user(void) -{ - uid_t uid = getuid(); - - if (uid < REGULAR_USER) - return 1; - else - return 0; -} - -static GBusType __get_bus_type(pkgmgr_client_type type) -{ - if (type == PC_REQUEST || _is_system_user()) - return G_BUS_TYPE_SYSTEM; - else - return G_BUS_TYPE_SESSION; -} - -int pkgmgr_client_connection_connect(struct pkgmgr_client_t *pc) -{ - GError *error = NULL; - GBusType bus_type; - -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - bus_type = __get_bus_type(pc->pc_type); - pc->conn = g_bus_get_sync(bus_type, NULL, &error); - if (error) { - ERR("gdbus connection error (%s)", error->message); - g_error_free(error); - return PKGMGR_R_ECOMM; - } - - return PKGMGR_R_OK; -} - -void pkgmgr_client_connection_disconnect(struct pkgmgr_client_t *pc) -{ - /* flush remaining buffer: blocking mode */ - g_dbus_connection_flush_sync(pc->conn, NULL, NULL); - g_object_unref(pc->conn); - pc->conn = NULL; -} - -struct signal_map { - const char *signal_str; - int signal_type; -}; - -struct signal_map map[] = { - {PKGMGR_INSTALLER_INSTALL_EVENT_STR, PKGMGR_CLIENT_STATUS_INSTALL}, - {PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, PKGMGR_CLIENT_STATUS_UNINSTALL}, - {PKGMGR_INSTALLER_UPGRADE_EVENT_STR, PKGMGR_CLIENT_STATUS_UPGRADE}, - {PKGMGR_INSTALLER_CLEAR_EVENT_STR, PKGMGR_CLIENT_STATUS_CLEAR_DATA}, - {PKGMGR_INSTALLER_MOVE_EVENT_STR, PKGMGR_CLIENT_STATUS_MOVE}, - {PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR, - PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS}, - {PKGMGR_INSTALLER_GET_SIZE_KEY_STR, PKGMGR_CLIENT_STATUS_GET_SIZE}, - {PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR, - PKGMGR_CLIENT_STATUS_CLEAR_CACHE}, - {PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, - PKGMGR_CLIENT_STATUS_ENABLE_APP}, - {PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, - PKGMGR_CLIENT_STATUS_DISABLE_APP}, - {PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR, - PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN}, - {PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR, - PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN}, - {PKGMGR_INSTALLER_RES_COPY_EVENT_STR, PKGMGR_CLIENT_STATUS_RES_COPY}, - {PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR, - PKGMGR_CLIENT_STATUS_RES_CREATE_DIR}, - {PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR, - PKGMGR_CLIENT_STATUS_RES_REMOVE}, - {PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR, - PKGMGR_CLIENT_STATUS_RES_UNINSTALL}, - {NULL, -1} -}; - -static int __get_signal_type(const char *name) -{ - int i; - - if (name == NULL) - return -1; - - for (i = 0; map[i].signal_str != NULL; i++) { - if (strcmp(map[i].signal_str, name) == 0) - return map[i].signal_type; - } - - return -1; -} - -static void __handle_size_info_callback(struct cb_info *cb_info, - const char *pkgid, const char *val) -{ - pkg_size_info_t size_info; - char buf[BUFMAX]; - char *saveptr; - char *token; - pkgmgr_total_pkg_size_info_receive_cb callback; - - snprintf(buf, sizeof(buf), "%s", val); - - DBG("%s, %s", pkgid, val); - - token = strtok_r(buf, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.data_size = atoll(token); - token = strtok_r(NULL, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.cache_size = atoll(token); - token = strtok_r(NULL, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.app_size = atoll(token); - token = strtok_r(NULL, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.ext_data_size = atoll(token); - token = strtok_r(NULL, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.ext_cache_size = atoll(token); - token = strtok_r(NULL, ":", &saveptr); - if (token == NULL) { - ERR("failed to parse size info"); - return; - } - size_info.ext_app_size = atoll(token); - - DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, " - "ext_cache: %lld, ext_app: %lld", - size_info.data_size, size_info.cache_size, - size_info.app_size, size_info.ext_data_size, - size_info.ext_cache_size, size_info.ext_app_size); - - if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) { - callback = (pkgmgr_total_pkg_size_info_receive_cb) - cb_info->size_info_cb; - callback(cb_info->client, &size_info, cb_info->data); - } else { - cb_info->size_info_cb(cb_info->client, pkgid, &size_info, - cb_info->data); - } -} - -static void __handle_pkg_signal(const gchar *signal_name, - GVariant *parameters, gpointer user_data) -{ - uid_t target_uid; - char *req_id; - char *pkg_type = NULL; - char *appid = NULL; - char *pkgid = NULL; - char *key = NULL; - char *val = NULL; - struct cb_info *cb_info = (struct cb_info *)user_data; - GVariantIter *iter = NULL; - int signal_type; - - g_variant_get(parameters, "(u&sa(sss)&s&s)", &target_uid, &req_id, &iter, - &key, &val); - while (g_variant_iter_loop(iter, "(&s&s&s)", &pkgid, &appid, &pkg_type)) { - if (cb_info->req_key) { - if (strcmp(cb_info->req_key, req_id) != 0) - continue; - } else { - signal_type = __get_signal_type(signal_name); - if (signal_type < 0 || !(cb_info->status_type & signal_type)) { - g_variant_iter_free(iter); - return; - } - } - - /* each cb_data can only has one callback */ - if (cb_info->event_cb) { - cb_info->event_cb(target_uid, cb_info->req_id, - pkg_type, pkgid, key, val, NULL, cb_info->data); - } else if (cb_info->app_event_cb && strcmp(appid, "") != 0) { - cb_info->app_event_cb(target_uid, cb_info->req_id, - pkg_type, pkgid, appid, key, val, NULL, - cb_info->data); - } else if (cb_info->size_info_cb) { - __handle_size_info_callback(cb_info, pkgid, val); - } - - /* TODO: unsubscribe request callback */ - } - g_variant_iter_free(iter); -} - -static void __handle_res_event_signal(const gchar *signal_name, - GVariant *parameters, gpointer user_data) -{ - uid_t target_uid; - char *req_id; - char *pkgid = NULL; - char *status = NULL; - char *path = NULL; - pkgmgr_res_event_path_state state; - struct cb_info *cb_info = (struct cb_info *)user_data; - int signal_type; - GVariant *extra_param = NULL; - pkgmgr_res_event_info_t *event_info; - GVariantIter *iter; - - if (!cb_info->res_event_cb) - return; - - g_variant_get(parameters, "(u&s&s&sv)", &target_uid, &req_id, &pkgid, &status, &extra_param); - if (!g_variant_type_equal(G_VARIANT_TYPE("(ia(si))"), - g_variant_get_type(extra_param))) { - ERR("invalid extra parameter"); - g_variant_unref(extra_param); - return; - } - if (cb_info->req_key) { - if (strcmp(cb_info->req_key, req_id) != 0) { - g_variant_unref(extra_param); - return; - } - } else { - signal_type = __get_signal_type(signal_name); - if (signal_type < 0 || !(cb_info->status_type & signal_type)) { - g_variant_unref(extra_param); - return; - } - } - - event_info = pkgmgr_res_event_info_new(); - if (event_info == NULL) { - ERR("out of memory"); - g_variant_unref(extra_param); - return; - } - - g_variant_get(extra_param, "(ia(si))", &event_info->error_code, &iter); - - while (g_variant_iter_loop(iter, "(&si)", &path, &state)) { - if (pkgmgr_res_event_info_add_path_state(event_info, - path, state) != PKGMGR_R_OK) { - ERR("Fail to add path state"); - g_variant_unref(extra_param); - g_variant_iter_free(iter); - pkgmgr_res_event_info_free(event_info); - return; - } - } - cb_info->res_event_cb(target_uid, cb_info->req_id, pkgid, signal_name, - status, event_info, cb_info->data); - g_variant_unref(extra_param); - g_variant_iter_free(iter); - pkgmgr_res_event_info_free(event_info); -} - -static void __signal_handler(GDBusConnection *conn, const gchar *sender_name, - const gchar *object_path, const gchar *interface_name, - const gchar *signal_name, GVariant *parameters, - gpointer user_data) -{ - if (g_variant_type_equal(G_VARIANT_TYPE("(usa(sss)ss)"), - g_variant_get_type(parameters))) { - __handle_pkg_signal(signal_name, parameters, user_data); - } else if (!strcmp(signal_name, PKGMGR_INSTALLER_RES_COPY_EVENT_STR) || - !strcmp(signal_name, PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR) || - !strcmp(signal_name, PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR) || - !strcmp(signal_name, PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR)) { - __handle_res_event_signal(signal_name, parameters, user_data); - } -} - -static void __set_signal_list(int event, GList **signal_list) -{ - int i; - if (event == PKGMGR_CLIENT_STATUS_ALL) - return; - - for (i = 0; map[i].signal_str != NULL; i++) { - if (event & map[i].signal_type) - *signal_list = g_list_append(*signal_list, - (char *)map[i].signal_str); - } -} - -static int __subscribe_signal(struct pkgmgr_client_t *pc, - struct cb_info *cb_info, const char *signal) -{ - guint sid = g_dbus_connection_signal_subscribe(pc->conn, NULL, - PKGMGR_INSTALLER_DBUS_INTERFACE, signal, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, NULL, - G_DBUS_SIGNAL_FLAGS_NONE, __signal_handler, - (gpointer)cb_info, NULL); - if (!sid) { - ERR("failed to subscribe singal"); - return PKGMGR_R_ERROR; - } - cb_info->sid_list = g_list_append(cb_info->sid_list, - GUINT_TO_POINTER(sid)); - - return PKGMGR_R_OK; -} - -int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, - struct cb_info *cb_info) -{ - GList *signal_list = NULL; - GList *tmp_list = NULL; - int ret; - char *signal_type; - __set_signal_list(pc->status_type, &signal_list); - - if (g_list_length(signal_list) == 0) - return __subscribe_signal(pc, cb_info, NULL); - - for (tmp_list = signal_list; tmp_list != NULL; - tmp_list = g_list_next(tmp_list)) { - signal_type = (char *)tmp_list->data; - ret = __subscribe_signal(pc, cb_info, signal_type); - if (ret != 0) { - g_list_free(signal_list); - return PKGMGR_R_ERROR; - } - } - - g_list_free(signal_list); - return PKGMGR_R_OK; -} - -void pkgmgr_client_connection_unset_callback(struct pkgmgr_client_t *pc, - struct cb_info *cb_info) -{ - GList *tmp = NULL; - guint tmp_sid; - for (tmp = cb_info->sid_list; tmp != NULL; tmp = g_list_next(tmp)) { - tmp_sid = GPOINTER_TO_UINT(tmp->data); - g_dbus_connection_signal_unsubscribe(pc->conn, tmp_sid); - } -} - -int pkgmgr_client_connection_send_request(struct pkgmgr_client_t *pc, - const char *method, GVariant *params, GVariant **result) -{ - GError *error = NULL; - GDBusProxy *proxy; - GVariant *r = NULL; - int retry_cnt = 0; - int ret = PKGMGR_R_ECOMM; - - /* convert floating ref into normal ref */ - g_variant_ref_sink(params); - - do { - proxy = g_dbus_proxy_new_sync(pc->conn, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, PKGMGR_DBUS_SERVICE, - PKGMGR_DBUS_OBJECT_PATH, - PKGMGR_DBUS_INTERFACE, NULL, &error); - if (proxy == NULL) { - ERR("failed to get proxy object, sleep and retry[%s]", - error->message); - g_error_free(error); - error = NULL; - usleep(CONNECTION_WAIT_USEC); - retry_cnt++; - continue; - } - - r = g_dbus_proxy_call_sync(proxy, method, params, - G_DBUS_CALL_FLAGS_NONE, - CONNECTION_TIMEOUT_MSEC, NULL, &error); - g_object_unref(proxy); - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) { - ERR("failed to send request, privilege denied[%s]", - error->message); - g_error_free(error); - ret = PKGMGR_R_EPRIV; - break; - } - if (r) { - *result = r; - ret = PKGMGR_R_OK; - break; - } - - ERR("failed to send request, sleep and retry[%s]", - error->message); - g_error_free(error); - error = NULL; - usleep(CONNECTION_WAIT_USEC); - retry_cnt++; - } while (retry_cnt <= CONNECTION_RETRY_MAX); - - /* decrease ref count to 0 to free resource */ - g_variant_unref(params); - - return ret; -} diff --git a/client/src/pkgmgr_client_debug.h b/client/src/pkgmgr_client_debug.h deleted file mode 100644 index b81f948..0000000 --- a/client/src/pkgmgr_client_debug.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: junsuk. oh <junsuk77.oh@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __PKGMGR_CLIENT_DEBUG_H__ -#define __PKGMGR_CLIENT_DEBUG_H__ - -#include <dlog.h> - -#ifdef LOG_TAG -#undef LOG_TAG -#endif /* LOG_TAG */ -#define LOG_TAG "PKGMGR" - -#ifndef ERR -#define ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef DBG -#define DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#ifndef INFO -#define INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) -#endif - -#define ret_if(expr) \ - do { \ - if (expr) { \ - ERR("(%s) ", #expr); \ - return; \ - } \ - } while (0) - -#define retm_if(expr, fmt, arg...) \ - do { \ - if (expr) { \ - ERR("(%s) "fmt, #expr, ##arg); \ - return; \ - } \ - } while (0) - -#define retv_if(expr, val) \ - do { \ - if (expr) { \ - ERR("(%s) ", #expr); \ - return (val); \ - } \ - } while (0) - -#define retvm_if(expr, val, fmt, arg...) \ - do { \ - if (expr) { \ - ERR("(%s) "fmt, #expr, ##arg); \ - return (val); \ - } \ - } while (0) - -#define trym_if(expr, fmt, arg...) \ - do { \ - if (expr) { \ - ERR("(%s) "fmt, #expr, ##arg); \ - goto catch; \ - } \ - } while (0) - -#define tryvm_if(expr, val, fmt, arg...) \ - do { \ - if (expr) { \ - ERR("(%s) "fmt, #expr, ##arg); \ - val; \ - goto catch; \ - } \ - } while (0) - -#endif /* __PKGMGR_CLIENT_DEBUG_H__ */ diff --git a/client/src/pkgmgr_client_internal.c b/client/src/pkgmgr_client_internal.c deleted file mode 100644 index 1c303f9..0000000 --- a/client/src/pkgmgr_client_internal.c +++ /dev/null @@ -1,419 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, - * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - - - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <ctype.h> -#include <xdgmime.h> - -#include <unistd.h> -#include <dlfcn.h> -#include <sys/time.h> -#include <tzplatform_config.h> -#include <pkgmgr-info.h> - -#include "package-manager.h" -#include "pkgmgr_client_debug.h" -#include "pkgmgr_client_internal.h" - -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -#define IS_WHITESPACE(CHAR) \ - ((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? \ - true : false) - -void _app_str_trim(char *input) -{ - char *trim_str = input; - - if (input == NULL) - return; - - while (*input != 0) { - if (!IS_WHITESPACE(*input)) { - *trim_str = *input; - trim_str++; - } - input++; - } - - *trim_str = 0; - return; -} - -int _get_mime_from_file(const char *filename, char *mimetype, int len) -{ - const char *mime; - if (filename == NULL) - return -1; - - if (access(filename, F_OK) != 0) - return -1; - - mime = xdg_mime_get_mime_type_for_file(filename, 0); - if (strcmp(mime, "application/octet-stream") == 0) - mime = xdg_mime_get_mime_type_from_file_name(filename); - - snprintf(mimetype, len, "%s", mime); - return 0; -} - -int _get_mime_extension(const char *mimetype, char *ext, int len) -{ - const char **extlist; - int totlen = 0; - const char *unaliased_mimetype; - - if (mimetype == NULL || ext == NULL || len <= 0) - return -1; - - unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype); - if (unaliased_mimetype == NULL) - return -1; - - extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype); - if (extlist == NULL) - return -1; - - if (extlist[0] == NULL) - return -1; - - ext[0] = 0; - while (*extlist != NULL) { - if (*(extlist + 1) == NULL) { - snprintf(&ext[totlen], len - totlen, "%s", *extlist); - break; - } else { - snprintf(&ext[totlen], len - totlen, "%s,", *extlist); - if (strlen(*extlist) > len - totlen - 1) - break; - totlen += strlen(*extlist) + 1; - extlist++; - } - } - - return 0; -} - -package_manager_pkg_info_t *_pkg_malloc_appinfo(int num) -{ - package_manager_app_info_t *app_info = NULL; - package_manager_app_info_t *first = NULL; - package_manager_app_info_t *last = NULL; - int i = 0; - - for (i = 0; i < num; i++) { - app_info = (package_manager_app_info_t *) - malloc(sizeof(package_manager_app_info_t)); - if (app_info == NULL) { - package_manager_app_info_t *temp_info; - package_manager_app_info_t *next; - - for (temp_info = first; temp_info != NULL; - temp_info = next) { - next = temp_info->next; - free(temp_info); - temp_info = NULL; - } - - return NULL; - } - - memset(app_info, 0x00, sizeof(package_manager_app_info_t)); - - if (first == NULL) - first = app_info; - - if (last == NULL) - last = app_info; - else { - last->next = app_info; - last = app_info; - } - } - - return first; - -} - -static pkg_plugin_set *plugin_set_list[24] = { 0, }; - -pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type, - const char *library_path) -{ - void *library_handle; - int i; - bool (*on_load)(pkg_plugin_set *plugin); - - if (library_path == NULL || pkg_type == NULL) { - ERR("invalid parameter"); - return NULL; - } - - for (i = 0; plugin_set_list[i]; i++) { - if (strcmp(plugin_set_list[i]->pkg_type, pkg_type) == 0) { - DBG("already loaded [%s]", library_path); - return plugin_set_list[i]; - } - } - - if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) { - ERR("dlopen is failed library_path[%s]", library_path); - return NULL; - } - - if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL || - dlerror() != NULL) { - ERR("can not find symbol"); - dlclose(library_handle); - return NULL; - } - - plugin_set_list[i] = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set)); - if (plugin_set_list[i] == NULL) { - ERR("malloc of the plugin_set_list element is failed"); - dlclose(library_handle); - return NULL; - } - - if (on_load(plugin_set_list[i]) != 0) { - ERR("pkg_plugin_on_load failed"); - free(plugin_set_list[i]); - dlclose(library_handle); - plugin_set_list[i] = NULL; - return NULL; - } - - plugin_set_list[i]->plugin_handle = library_handle; - snprintf(plugin_set_list[i]->pkg_type, - sizeof(plugin_set_list[i]->pkg_type), "%s", pkg_type); - - DBG("library [%s] is loaded", library_path); - - return plugin_set_list[i]; -} - -int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path) -{ - FILE *fp = NULL; - char buffer[1024] = { 0 }; - - if (pkg_type == NULL || library_path == NULL) { - ERR("invalid argument\n"); - return -1; - } - - fp = fopen(PKG_CONF_PATH, "r"); - if (fp == NULL) { - ERR("no matching backendlib\n"); - return PKGMGR_R_ERROR; - } - - char *path = NULL; - while (fgets(buffer, 1024, fp) != NULL) { - if (buffer[0] == '#') - continue; - - _app_str_trim(buffer); - - if ((path = strstr(buffer, PKG_BACKENDLIB)) != NULL) { - DBG("[%s]\n", buffer); - DBG("[%s]\n", path); - path = path + strlen(PKG_BACKENDLIB); - DBG("[%s]\n", path); - - break; - } - - memset(buffer, 0x00, 1024); - } - - if (fp != NULL) - fclose(fp); - - if (path == NULL) { - ERR("no matching backendlib\n"); - return PKGMGR_R_ERROR; - } - - snprintf(library_path, 1024, "%slib%s.so", path, pkg_type); - - return PKGMGR_R_OK; - -} - -pkg_plugin_set *_package_manager_load_library(const char *pkg_type) -{ - char package_path[1024] = { 0, }; - pkg_plugin_set *plugin_set; - - if (pkg_type == NULL) { - ERR("cannot load library - pkg_type is null"); - return NULL; - } - - if (_pkg_plugin_get_library_path(pkg_type, package_path) != - PKGMGR_R_OK) { - ERR("cannot find path"); - return NULL; - } - - plugin_set = _pkg_plugin_load_library(pkg_type, package_path); - if (plugin_set == NULL) { - ERR("cannot load library"); - return NULL; - } - - return plugin_set; -} - -typedef struct _detail_info_map_t { - char *name; - void *field; - char *type; -} detail_info_map_t; - -/* - typedef struct _package_manager_pkg_detail_info_t { - char pkg_type[PKG_TYPE_STRING_LEN_MAX]; - char pkgid[PKG_NAME_STRING_LEN_MAX]; - char version[PKG_VERSION_STRING_LEN_MAX]; - char pkg_description[PKG_VALUE_STRING_LEN_MAX]; - char min_platform_version[PKG_VERSION_STRING_LEN_MAX]; - time_t installed_time; - int installed_size; - int app_size; - int data_size; - char optional_id[PKG_NAME_STRING_LEN_MAX]; - void *pkg_optional_info; - } package_manager_pkg_detail_info_t; -*/ - -static package_manager_pkg_detail_info_t tmp_pkg_detail_info; - -static detail_info_map_t info_map[] = { - {"pkg_type", tmp_pkg_detail_info.pkg_type, "string"}, - {"pkgid", tmp_pkg_detail_info.pkgid, "string"}, - {"version", tmp_pkg_detail_info.version, "string"}, - {"pkg_description", tmp_pkg_detail_info.pkg_description, "string"}, - {"min_platform_version", tmp_pkg_detail_info.min_platform_version, - "string"}, - {"installed_time", &tmp_pkg_detail_info.installed_time, "time_t"}, - {"installed_size", &tmp_pkg_detail_info.installed_size, "int"}, - {"app_size", &tmp_pkg_detail_info.app_size, "int"}, - {"data_size", &tmp_pkg_detail_info.data_size, "int"}, - {"optional_id", tmp_pkg_detail_info.optional_id, "string"} -}; - -char *_get_info_string(const char *key, - const package_manager_pkg_detail_info_t * - pkg_detail_info) -{ - detail_info_map_t *tmp; - int i = 0; - - if (pkg_detail_info == NULL) - return NULL; - - memcpy(&tmp_pkg_detail_info, pkg_detail_info, - sizeof(package_manager_pkg_detail_info_t)); - - for (i = 0; i < sizeof(info_map) / sizeof(detail_info_map_t); i++) { - tmp = &info_map[i]; - if (strcmp(key, tmp->name) == 0) { - if (strcmp(tmp->type, "string") == 0) { - return strdup((char *)(tmp->field)); - } else if (strcmp(tmp->type, "bool") == 0) { - char temp[PKG_VALUE_STRING_LEN_MAX]; - snprintf(temp, PKG_VALUE_STRING_LEN_MAX - 1, - "%d", (int)*(bool *) (tmp->field)); - return strdup(temp); - } else if (strcmp(tmp->type, "int") == 0) { - char temp[PKG_VALUE_STRING_LEN_MAX]; - snprintf(temp, PKG_VALUE_STRING_LEN_MAX - 1, - "%d", (int)*(int *)(tmp->field)); - return strdup(temp); - } else if (strcmp(tmp->type, "time_t") == 0) { - char temp[PKG_VALUE_STRING_LEN_MAX]; - snprintf(temp, PKG_VALUE_STRING_LEN_MAX - 1, - "%d", (int)*(time_t *) (tmp->field)); - return strdup(temp); - } else - return NULL; - } - } - return NULL; -} - -int _get_info_int(const char *key, - const package_manager_pkg_detail_info_t *pkg_detail_info) -{ - detail_info_map_t *tmp; - int i = 0; - - if (pkg_detail_info == NULL) - return -1; - - memcpy(&tmp_pkg_detail_info, pkg_detail_info, - sizeof(package_manager_pkg_detail_info_t)); - for (i = 0; i < sizeof(info_map) / sizeof(detail_info_map_t); i++) { - tmp = &info_map[i]; - if (strcmp(key, tmp->name) == 0) { - if (strcmp(tmp->type, "int") == 0) - return (int)*(int *)(tmp->field); - else - return -1; - } - } - return -1; -} - -time_t _get_info_time(const char *key, - const package_manager_pkg_detail_info_t *pkg_detail_info) -{ - detail_info_map_t *tmp; - int i = 0; - - if (pkg_detail_info == NULL) - return -1; - - memcpy(&tmp_pkg_detail_info, pkg_detail_info, - sizeof(package_manager_pkg_detail_info_t)); - for (i = 0; i < sizeof(info_map) / sizeof(detail_info_map_t); i++) { - tmp = &info_map[i]; - if (strcmp(key, tmp->name) == 0) { - if (strcmp(tmp->type, "time_t") == 0) - return (time_t) *(time_t *) (tmp->field); - else - return (time_t) -1; - } - } - return (time_t) -1; -} - - diff --git a/client/src/pkgmgr_client_internal.h b/client/src/pkgmgr_client_internal.h deleted file mode 100644 index 02c4205..0000000 --- a/client/src/pkgmgr_client_internal.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, - * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __PKGMGR_CLIENT_INTERNAL_H__ -#define __PKGMGR_CLIENT_INTERNAL_H__ - -#include <unistd.h> -#include <ctype.h> - -#include <glib.h> -#include <gio/gio.h> - -#include "package-manager-plugin.h" -#include "package-manager.h" - -#define BUFMAX 4096 - -struct cb_info { - int req_id; - char *req_key; - int status_type; - pkgmgr_handler event_cb; - pkgmgr_app_handler app_event_cb; - pkgmgr_pkg_size_info_receive_cb size_info_cb; - pkgmgr_res_handler res_event_cb; - void *data; - struct pkgmgr_client_t *client; - GList *sid_list; -}; - -struct pkgmgr_client_t { - pkgmgr_client_type pc_type; - int status_type; - GDBusConnection *conn; - GList *cb_info_list; - GVariantBuilder *res_copy_builder; - GVariantBuilder *res_remove_builder; - GVariantBuilder *res_create_dir_builder; - char *tep_path; - bool tep_move; - bool debug_mode; - bool skip_optimization; -}; - -struct manifest_and_type { - const char *manifest; - const char *type; -}; - -int pkgmgr_client_connection_connect(struct pkgmgr_client_t *pc); -void pkgmgr_client_connection_disconnect(struct pkgmgr_client_t *pc); -int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, - struct cb_info *cb_info); -void pkgmgr_client_connection_unset_callback(struct pkgmgr_client_t *pc, - struct cb_info *cb_info); -int pkgmgr_client_connection_send_request(struct pkgmgr_client_t *pc, - const char *method, GVariant *params, GVariant **result); - - -typedef package_manager_pkg_info_t package_manager_app_info_t; - - -package_manager_pkg_info_t *_pkg_malloc_appinfo(int num); - -pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type, - const char *library_path); - -int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path); - -pkg_plugin_set *_package_manager_load_library(const char *pkg_type); - -char *_get_info_string(const char *key, - const package_manager_pkg_detail_info_t * - pkg_detail_info); - -int _get_info_int(const char *key, - const package_manager_pkg_detail_info_t *pkg_detail_info); - -time_t _get_info_time(const char *key, - const package_manager_pkg_detail_info_t * - pkg_detail_info); - - -#define PKG_FRONTEND "frontend:" -#define PKG_BACKEND "backend:" -#define PKG_BACKENDLIB "backendlib:" -#define PKG_PARSERLIB "parserlib:" -#define PKG_CONF_PATH "/etc/package-manager/pkg_path.conf" - -#define PKG_STATUS "STATUS" - -#define PKG_STRING_LEN_MAX 1024 -#define PKG_EXT_LEN_MAX 20 -#define PKG_ARGC_MAX 16 - -void _app_str_trim(char *input); - -int _get_mime_from_file(const char *filename, char *mimetype, int len); -int _get_mime_extension(const char *mimetype, char *ext, int len); - -#endif /* __PKGMGR_CLIENT_INTERNAL_H__ */ diff --git a/client/src/signal_receiver.cc b/client/src/signal_receiver.cc new file mode 100644 index 0000000..ca20d9a --- /dev/null +++ b/client/src/signal_receiver.cc @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "signal_receiver.hh" + +namespace pkgmgr { +namespace client { + +SignalReceiver::SignalReceiver() : PkgSignal("", true) { +} + +SignalReceiver::~SignalReceiver() { +} + +void SignalReceiver::OnAsyncResult(int targetUid, std::string reqId, + std::vector<pkg_signal::PkgInfo> pkgs, std::string key, std::string val) { + if (handlers_.find(reqId) == handlers_.end()) + return; + auto [id, cb, app_cb, data] = handlers_[reqId]; + + for (auto& i : pkgs) { + if (cb) { + cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(), + key.c_str(), val.c_str(), nullptr, data); + } else { + app_cb(targetUid, id, i.GetPkgType().c_str(), i.GetPkgid().c_str(), + i.GetAppid().c_str(), key.c_str(), val.c_str(), nullptr, data); + } + } + + //TODO: dispatch using global_handlers_ +} + +void SignalReceiver::OnAsyncResultForResource(int targetUid, std::string reqId, + std::string pkgid, std::string status, pkg_signal::ExtraData extra) { + //TODO +} + +int SignalReceiver::AddEventHandler(std::string req_key, + pkgmgr_handler event_cb, void* data) { + return AddEventHandler(std::move(req_key), event_cb, nullptr, data); +} + +int SignalReceiver::AddEventHandler(std::string req_key, + pkgmgr_app_handler app_event_cb, void* data) { + return AddEventHandler(std::move(req_key), nullptr, app_event_cb, data); +} + +int SignalReceiver::AddEventHandler(std::string req_key, + pkgmgr_pkg_size_info_receive_cb event_cb, void* data) { + //TODO + return 1; +} + +int SignalReceiver::AddEventHandler(std::string req_key, + pkgmgr_handler event_cb, pkgmgr_app_handler app_event_cb, void* data) { + static int sId = 1; + if (req_key.empty()) + global_handlers_.push_back({ sId, event_cb, app_event_cb, data }); + else + handlers_[req_key] = { sId, event_cb, app_event_cb, data }; + return sId++; +} + +int SignalReceiver::AddEventHandler(std::string req_key, + pkgmgr_res_handler event_cb, void* data) { + //TODO + return 1; +} + +} // namespace client +} // namespace pkgmgr + diff --git a/client/src/signal_receiver.hh b/client/src/signal_receiver.hh new file mode 100644 index 0000000..8d4e8f4 --- /dev/null +++ b/client/src/signal_receiver.hh @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef CLIENT_SRC_SIGNAL_RECEIVER_H_ +#define CLIENT_SRC_SIGNAL_RECEIVER_H_ + +#include "package-manager.h" + +#include <map> +#include <memory> +#include <string> +#include <tuple> + +#include "PkgSignal.h" + + +namespace pkgmgr { +namespace client { + +namespace pkg_group = rpc_port::PkgSignal::group; +namespace pkg_signal = rpc_port::PkgSignal; + +class SignalReceiver : public pkg_group::PkgSignal { + public: + SignalReceiver(); + virtual ~SignalReceiver(); + + void OnAsyncResult(int targetUid, std::string reqId, + std::vector<pkg_signal::PkgInfo> pkgs, std::string key, + std::string val) override; + + void OnAsyncResultForResource(int targetUid, std::string reqId, + std::string pkgid, std::string status, + pkg_signal::ExtraData extra) override; + + int AddEventHandler(std::string req_key, pkgmgr_handler event_cb, void* data); + int AddEventHandler(std::string req_key, pkgmgr_app_handler app_event_cb, + void* data); + int AddEventHandler(std::string req_key, + pkgmgr_pkg_size_info_receive_cb event_cb, void* data); + int AddEventHandler(std::string req_key, pkgmgr_res_handler event_cb, + void* data); + + private: + int AddEventHandler(std::string req_key, pkgmgr_handler event_cb, + pkgmgr_app_handler app_event_cb, void* data); + + private: + std::map<std::string, std::tuple<int, pkgmgr_handler, pkgmgr_app_handler, + void*>> handlers_; + std::list<std::tuple<int, pkgmgr_handler, pkgmgr_app_handler, void*>> global_handlers_; +}; + +} // namespace client +} // namespace pkgmgr + +#endif // CLIENT_SRC_CONNECTOR_H_
\ No newline at end of file diff --git a/cmake/Modules/ApplyPkgConfig.cmake b/cmake/Modules/ApplyPkgConfig.cmake new file mode 100644 index 0000000..97679d7 --- /dev/null +++ b/cmake/Modules/ApplyPkgConfig.cmake @@ -0,0 +1,35 @@ +# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# +# This function applies external (out of source tree) dependencies +# to given target. Arguments are: +# TARGET - valid cmake target +# PRIVACY - dependency can be inherited by dependent targets or not: +# PUBLIC - this should be used by default, cause compile/link flags passing +# PRIVATE - do not passes any settings to dependent targets, +# may be usefull for static libraries from the inside of the project +# Argument ARGV2 and following are supposed to be names of checked pkg config +# packages. This function will use variables created by check_pkg_modules(). +# - ${DEP_NAME}_LIBRARIES +# - ${DEP_NAME}_INCLUDE_DIRS +# - ${DEP_NAME}_CFLAGS +# +FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY) + MATH(EXPR DEST_INDEX "${ARGC}-1") + FOREACH(I RANGE 2 ${DEST_INDEX}) + IF(NOT ${ARGV${I}}_FOUND) + MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND") + ENDIF(NOT ${ARGV${I}}_FOUND) + TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}") + TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}") + STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}") + SET(CFLAGS_LIST ${CFLAGS_STR}) + SEPARATE_ARGUMENTS(CFLAGS_LIST) + FOREACH(OPTION ${CFLAGS_LIST}) + TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION}) + ENDFOREACH(OPTION) + SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true) + ENDFOREACH(I RANGE 2 ${DEST_INDEX}) +ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY) diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt index 9c734d0..e5e9553 100644 --- a/installer/CMakeLists.txt +++ b/installer/CMakeLists.txt @@ -1,32 +1,30 @@ -### Description -# Communication modules for pkg-mgr client lib and server process -# By Youmin Ha <youmin.ha@samsung.com> +include(FindPkgConfig) -cmake_minimum_required(VERSION 2.6) -#set(CMAKE_SKIP_BUILD_RPATH true) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) +AUX_SOURCE_DIRECTORY(src SRCS) -### Get required CFLAGS, LDFLAGS from pkg-config +PKG_CHECK_MODULES(INSTALLER_DEPS REQUIRED + glib-2.0 + gio-2.0 + dlog + pkgmgr-info + libtzplatform-config + rpc-port + capi-appfw-event +) -include(FindPkgConfig) -pkg_check_modules(installer_pkgs REQUIRED glib-2.0 gio-2.0 dlog pkgmgr-info libtzplatform-config) -foreach(flag ${installer_pkgs_CFLAGS}) - set(installer_pkgs_CFLAGS_str "${installer_pkgs_CFLAGS_str} ${flag}") -endforeach() +FOREACH(FLAGS ${INSTALLER_DEPS_CFLAGS}) + SET(INSTALLER_CFLAGS "${INSTALLER_CFLAGS} ${FLAGS}") +ENDFOREACH(FLAGS) -PKG_CHECK_MODULES(AGENT_DEPS REQUIRED glib-2.0 gio-2.0 dlog libsystemd) -FOREACH(FLAG ${AGENT_DEPS_CFLAGS}) - SET(AGENT_CFLAGS "${AGENT_CFLAGS} ${FLAG}") -ENDFOREACH() +SET(CMAKE_C_FLAGS "${INSTALLER_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${INSTALLER_CFLAGS} -std=c++17 -fPIC") -### Build modules +INCLUDE_DIRECTORIES(include) -## pkgmgr_installer object (by youmin.ha) -# This library is for installer backend -add_library(pkgmgr_installer SHARED pkgmgr_installer.c) +### Build modules +add_library(pkgmgr_installer SHARED ${SRCS}) set_target_properties(pkgmgr_installer PROPERTIES SOVERSION ${MAJORVER}) set_target_properties(pkgmgr_installer PROPERTIES VERSION ${FULLVER}) -set_target_properties(pkgmgr_installer PROPERTIES COMPILE_FLAGS "${installer_pkgs_CFLAGS_str} -fPIC") target_link_libraries(pkgmgr_installer ${installer_pkgs_LDFLAGS}) ### Create pc file @@ -34,15 +32,8 @@ configure_file(pkgmgr-installer.pc.in ${CMAKE_CURRENT_BINARY_DIR}/pkgmgr-install ## Install INSTALL(TARGETS pkgmgr_installer DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES pkgmgr_installer.h DESTINATION include/pkgmgr) -INSTALL(FILES pkgmgr_installer_info.h DESTINATION include/pkgmgr) -INSTALL(FILES pkgmgr_installer_error.h DESTINATION include/pkgmgr) -INSTALL(FILES pkgmgr_installer_type.h DESTINATION include/pkgmgr) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer.h DESTINATION include/pkgmgr) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_info.h DESTINATION include/pkgmgr) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_error.h DESTINATION include/pkgmgr) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_type.h DESTINATION include/pkgmgr) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgmgr-installer.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -## pkgmgr_installer_signal_agent -ADD_EXECUTABLE(pkgmgr-installer-signal-agent pkgmgr_installer_signal_agent.c) -SET_TARGET_PROPERTIES(pkgmgr-installer-signal-agent PROPERTIES COMPILE_FLAGS "${AGENT_CFLAGS} -fPIE") -TARGET_LINK_LIBRARIES(pkgmgr-installer-signal-agent ${AGENT_DEPS_LDFLAGS} "-pie") - -INSTALL(TARGETS pkgmgr-installer-signal-agent DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/installer/pkgmgr-installer.pc.in b/installer/pkgmgr-installer.pc.in index f812a3b..fe02345 100644 --- a/installer/pkgmgr-installer.pc.in +++ b/installer/pkgmgr-installer.pc.in @@ -11,6 +11,6 @@ includedir=@INCLUDEDIR@ Name: package manager installer library Description: SLP package manager's installer lib for each backends Version: @FULLVER@ -Requires: +Requires: capi-appfw-event Libs: -L${libdir} -lpkgmgr_installer Cflags: -I${includedir}/pkgmgr diff --git a/installer/pkgmgr_installer.c b/installer/pkgmgr_installer.c deleted file mode 100644 index 82285e0..0000000 --- a/installer/pkgmgr_installer.c +++ /dev/null @@ -1,1418 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, - * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <getopt.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> - -#include <glib.h> -#include <gio/gio.h> -#include <tzplatform_config.h> - -#include "package-manager.h" -#include "pkgmgr_installer.h" -#include "pkgmgr_installer_config.h" -#include "pkgmgr_installer_debug.h" -#include "pkgmgr_installer_info.h" -#include "pkgmgr_installer_error.h" -#include "package-manager-types.h" - -#include <pkgmgr-info.h> - -/* API export macro */ -#ifndef API -#define API __attribute__ ((visibility("default"))) -#endif - -#define MAX_STRLEN 1024 -#define MAX_QUERY_LEN 4096 - -#define CHK_PI_RET(r) \ - do { if (NULL == pi) return (r); } while (0) - -#define OPTVAL_PRELOAD 1000 -#define OPTVAL_FORCE_REMOVAL 1001 -#define OPTVAL_PRELOAD_RW 1002 -#define OPTVAL_NO_REMOVAL 1003 -#define OPTVAL_KEEP_RWDATA 1004 -#define OPTVAL_PARTIAL_RW 1005 -#define OPTVAL_MIGRATE_EXTIMG 1006 -#define OPTVAL_SKIP_CHECK_REFERENCE 1007 -#define OPTVAL_RECOVER_DB 1008 -#define OPTVAL_RECOVERY_CLEANUP 1009 - -/* Supported options */ -const char *short_opts = "k:l:i:d:c:m:t:o:r:p:s:b:e:M:y:u:w:D:A:qGS"; -const struct option long_opts[] = { - { "session-id", 1, NULL, 'k' }, - { "license-path", 1, NULL, 'l' }, - { "install", 1, NULL, 'i' }, - { "uninstall", 1, NULL, 'd' }, - { "clear", 1, NULL, 'c' }, - { "move", 1, NULL, 'm' }, - { "move-type", 1, NULL, 't' }, - { "optional-data", 0, NULL, 'o' }, - { "reinstall", 0, NULL, 'r' }, - { "caller-pkgid", 1, NULL, 'p' }, - { "tep-path", 1, NULL, 'e' }, - { "tep-move", 1, NULL, 'M' }, - { "smack", 1, NULL, 's' }, - { "manifest-direct-install", 1, NULL, 'y' }, - { "mount-install", 1, NULL, 'w' }, - { "recovery", 1, NULL, 'b' }, - { "debug-mode", 0, NULL, 'G' }, - { "skip-optimization", 0, NULL, 'S' }, - { "preload", 0, NULL, OPTVAL_PRELOAD }, /* for preload RO */ - { "force-remove", 0, NULL, OPTVAL_FORCE_REMOVAL }, /* for preload RO/RW */ - { "preload-rw", 0, NULL, OPTVAL_PRELOAD_RW }, /* for preload RW */ - { "no-remove", 0, NULL, OPTVAL_NO_REMOVAL }, /* for preload RW */ - { "keep-rwdata", 0, NULL, OPTVAL_KEEP_RWDATA }, /* for preload RW */ - { "partial-rw", 0, NULL, OPTVAL_PARTIAL_RW }, /* for preload RO */ - { "migrate-extimg", 1, NULL, OPTVAL_MIGRATE_EXTIMG }, - { "skip-check-reference", 0, NULL, OPTVAL_SKIP_CHECK_REFERENCE }, - { "recover-db", 1, NULL, OPTVAL_RECOVER_DB }, - { "recovery-cleanup", 0, NULL, OPTVAL_RECOVERY_CLEANUP }, - { 0, 0, 0, 0 } /* sentinel */ -}; - -struct pkgmgr_installer { - int request_type; - int move_type; - int is_upgrade; - char *pkgmgr_info; - char *session_id; - char *license_path; - char *optional_data; - char *caller_pkgid; - uid_t target_uid; - char *tep_path; - int tep_move; - int is_tep_included; - int is_preload; - int force_removal; - int is_preload_rw; - int no_removal; - int keep_rwdata; - int partial_rw; - int debug_mode; - int skip_check_reference; - int skip_optimization; - int recovery_cleanup; - GDBusConnection *conn; - GHashTable *pkg_list; - GList *pkgs; -}; - -typedef struct pkg_signal_info { - char *pkgid; - char *pkg_type; -} pkg_signal_info; - -static uid_t g_target_uid; -static int g_debug_mode; -static int g_skip_optimization; -static pkgmgr_privilege_level g_privilege_level = PM_PRIVILEGE_UNKNOWN; - -static const char *__get_signal_name(pkgmgr_installer *pi, const char *key, - const char *pkg_type) -{ - if (strcmp(key, PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0) - return key; - else if (strcmp(key, PKGMGR_INSTALLER_GET_SIZE_KEY_STR) == 0) - return key; - else if (strcmp(key, PKGMGR_INSTALLER_APPID_KEY_STR) == 0) - return PKGMGR_INSTALLER_UNINSTALL_EVENT_STR; - else if (strcmp(pkg_type, PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR) == 0) - return pkg_type; - else if (pi->is_upgrade) - return PKGMGR_INSTALLER_UPGRADE_EVENT_STR; - - - switch (pi->request_type) { - case PKGMGR_REQ_INSTALL: - case PKGMGR_REQ_MANIFEST_DIRECT_INSTALL: - case PKGMGR_REQ_MOUNT_INSTALL: - case PKGMGR_REQ_REINSTALL: - case PKGMGR_REQ_ENABLE_PKG: - case PKGMGR_REQ_RECOVER: - return PKGMGR_INSTALLER_INSTALL_EVENT_STR; - case PKGMGR_REQ_UNINSTALL: - case PKGMGR_REQ_DISABLE_PKG: - return PKGMGR_INSTALLER_UNINSTALL_EVENT_STR; - case PKGMGR_REQ_UPGRADE: - return PKGMGR_INSTALLER_UPGRADE_EVENT_STR; - case PKGMGR_REQ_MOVE: - return PKGMGR_INSTALLER_MOVE_EVENT_STR; - case PKGMGR_REQ_ENABLE_APP: - return PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR; - case PKGMGR_REQ_DISABLE_APP: - return PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR; - case PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN: - return PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR; - case PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN: - return PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR; - case PKGMGR_REQ_CLEAR: - return PKGMGR_INSTALLER_CLEAR_EVENT_STR; - case PKGMGR_REQ_GETSIZE: - return PKGMGR_INSTALLER_GET_SIZE_KEY_STR; - case PKGMGR_REQ_RES_COPY: - return PKGMGR_INSTALLER_RES_COPY_EVENT_STR; - case PKGMGR_REQ_RES_CREATE_DIR: - return PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR; - case PKGMGR_REQ_RES_REMOVE: - return PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR; - case PKGMGR_REQ_RES_UNINSTALL: - return PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR; - } - - ERR("cannot find type"); - - return NULL; -} - -static int __send_signal_for_event(pkgmgr_installer *pi, const char *pkg_type, - const char *pkgid, const char *appid, const char *key, - const char *val) -{ - char *sid; - const char *tmp_appid = appid; - const char *signal_name; - GVariant *v; - GVariantBuilder *builder; - GError *err = NULL; - - if (!pi || pi->conn == NULL) - return -1; - - sid = pi->session_id; - if (!sid) - sid = ""; - - signal_name = __get_signal_name(pi, key, pkg_type); - if (!signal_name) { - ERR("unknown signal type"); - return -1; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)")); - g_variant_builder_add(builder, "(sss)", pkgid, - (tmp_appid ? tmp_appid : ""), pkg_type); - v = g_variant_new("(usa(sss)ss)", - pi->target_uid, sid, builder, key, val); - g_variant_builder_unref(builder); - if (g_dbus_connection_emit_signal(pi->conn, NULL, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, - PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name, - v, &err) != TRUE) { - ERR("failed to send dbus signal"); - if (err) { - ERR("err: %s", err->message); - g_error_free(err); - } - return -1; - } - - return 0; -} - -static int __send_signal_to_agent(uid_t uid, void *data, size_t len) -{ - int fd; - struct sockaddr_un sa; - int r; - - fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); - if (fd == -1) { - ERR("failed to create socket: %d", errno); - return -1; - } - - sa.sun_family = AF_UNIX; - snprintf(sa.sun_path, sizeof(sa.sun_path), "/run/pkgmgr/agent/%d", uid); - - r = connect(fd, (struct sockaddr *)&sa, sizeof(sa)); - if (r == -1) { - ERR("failed to connect socket(%s): %d", sa.sun_path, errno); - close(fd); - return -1; - } - - r = send(fd, data, len, MSG_NOSIGNAL); - if (r < 0) { - ERR("failed to send data: %d", errno); - close(fd); - return -1; - } - - close(fd); - - return 0; -} - -static int __send_signal_for_event_for_uid(pkgmgr_installer *pi, uid_t uid, - const char *pkg_type, const char *pkgid, const char *appid, - const char *key, const char *val) -{ - char *sid; - const char *signal_name; - const char *tmp_appid = appid; - size_t name_size; - GVariantBuilder *builder; - GVariant *gv; - gsize gv_len; - gpointer gv_data; - void *data; - void *ptr; - size_t data_len; - - if (!pi || pi->conn == NULL) - return -1; - - sid = pi->session_id; - if (!sid) - sid = ""; - - data_len = sizeof(size_t) + sizeof(gsize); - - signal_name = __get_signal_name(pi, key, pkg_type); - if (!signal_name) { - ERR("unknown signal name"); - return -1; - } - - /* including null byte */ - name_size = strlen(signal_name) + 1; - data_len += name_size; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)")); - g_variant_builder_add(builder, "(sss)", pkgid, - (tmp_appid ? tmp_appid : ""), pkg_type); - gv = g_variant_new("(usa(sss)ss)", pi->target_uid, sid, - builder, key, val); - g_variant_builder_unref(builder); - if (gv == NULL) { - ERR("failed to create GVariant instance"); - return -1; - } - gv_len = g_variant_get_size(gv); - gv_data = g_malloc(gv_len); - g_variant_store(gv, gv_data); - g_variant_unref(gv); - data_len += gv_len; - - data = malloc(data_len); - if (data == NULL) { - ERR("out of memory"); - g_free(gv_data); - return -1; - } - ptr = data; - memcpy(ptr, &name_size, sizeof(size_t)); - ptr += sizeof(size_t); - memcpy(ptr, &gv_len, sizeof(gsize)); - ptr += sizeof(gsize); - memcpy(ptr, signal_name, name_size); - ptr += name_size; - memcpy(ptr, gv_data, gv_len); - g_free(gv_data); - - if (__send_signal_to_agent(uid, data, data_len)) { - ERR("failed to send signal to agent"); - free(data); - return -1; - } - - free(data); - - return 0; -} - -static void __free_pkg_list(gpointer data) -{ - pkg_signal_info *info = (pkg_signal_info *)data; - free(info->pkgid); - free(info->pkg_type); - free(info); -} - -API pkgmgr_installer *pkgmgr_installer_new(void) -{ - pkgmgr_installer *pi; - GError *err = NULL; - - pi = calloc(1, sizeof(struct pkgmgr_installer)); - if (pi == NULL) - return NULL; - - pi->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (pi->conn == NULL) { - ERR("failed to get bus: %s", err->message); - g_error_free(err); - free(pi); - return NULL; - } - - pi->tep_path = NULL; - pi->tep_move = 0; - pi->request_type = PKGMGR_REQ_INVALID; - pi->pkg_list = g_hash_table_new_full( - g_str_hash, g_str_equal, NULL, __free_pkg_list); - return pi; -} - -API pkgmgr_installer *pkgmgr_installer_offline_new(void) -{ - pkgmgr_installer *pi; - - pi = calloc(1, sizeof(struct pkgmgr_installer)); - if (pi == NULL) - return NULL; - - pi->tep_path = NULL; - pi->tep_move = 0; - pi->request_type = PKGMGR_REQ_INVALID; - - return pi; -} - -API int pkgmgr_installer_free(pkgmgr_installer *pi) -{ - CHK_PI_RET(-EINVAL); - - /* free members */ - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - if (pi->session_id) - free(pi->session_id); - if (pi->optional_data) - free(pi->optional_data); - if (pi->caller_pkgid) - free(pi->caller_pkgid); - if (pi->tep_path) - free(pi->tep_path); - - if (pi->conn) { - g_dbus_connection_flush_sync(pi->conn, NULL, NULL); - g_object_unref(pi->conn); - } - - if (pi->pkgs) - g_list_free_full(pi->pkgs, free); - - if (pi->pkg_list) - g_hash_table_destroy(pi->pkg_list); - - free(pi); - - return 0; -} - -static void __parse_multiple_pkgs(pkgmgr_installer *pi, int argc, char **argv) -{ - while ((optind <= argc) && (*argv[optind - 1] != '-')) { - pi->pkgs = g_list_append(pi->pkgs, strdup(argv[optind - 1])); - optind++; - } - optind--; -} - -API int -pkgmgr_installer_receive_request(pkgmgr_installer *pi, - const int argc, char **argv) -{ - CHK_PI_RET(-EINVAL); - - int r = 0; - - /* Parse argv */ - optind = 1; /* Initialize optind to clear prev. index */ - int opt_idx = 0; - int c; - int mode = 0; - - pi->target_uid = getuid(); - g_target_uid = pi->target_uid; - g_debug_mode = 0; - g_skip_optimization = 0; - - if (pi->pkgs) { - g_list_free_full(pi->pkgs, free); - pi->pkgs = NULL; - } - - while (1) { - c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx); - /* printf("c=%d %c\n", c, c); //debug */ - if (-1 == c) - break; /* Parse is end */ - switch (c) { - case OPTVAL_PRELOAD: /* request for preload app */ - pi->is_preload = 1; - DBG("preload request [%d]", pi->is_preload); - break; - case OPTVAL_FORCE_REMOVAL: /* request for force-remove */ - pi->force_removal = 1; - DBG("force-remove request [%d]", pi->force_removal); - break; - case OPTVAL_PRELOAD_RW: /* request for preload-rw app */ - pi->is_preload_rw = 1; - DBG("preload-rw request [%d]", pi->is_preload_rw); - break; - case OPTVAL_NO_REMOVAL: /* request for no-remove */ - pi->no_removal = 1; - DBG("no-remove request [%d]", pi->no_removal); - break; - case OPTVAL_KEEP_RWDATA: /* request for keep-rwdata */ - pi->keep_rwdata = 1; - DBG("keep-rwdata request [%d]", pi->keep_rwdata); - break; - case OPTVAL_PARTIAL_RW: /* request for partial-rw */ - pi->partial_rw = 1; - DBG("partial-rw request [%d]", pi->partial_rw); - break; - case OPTVAL_MIGRATE_EXTIMG: - /* request for legacy extimg migration */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = OPTVAL_MIGRATE_EXTIMG; - pi->request_type = PKGMGR_REQ_MIGRATE_EXTIMG; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - DBG("legacy extimg migration requested"); - break; - case OPTVAL_SKIP_CHECK_REFERENCE: - pi->skip_check_reference = 1; - break; - case OPTVAL_RECOVER_DB: - pi->request_type = PKGMGR_REQ_RECOVER_DB; - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - case OPTVAL_RECOVERY_CLEANUP: - pi->recovery_cleanup = 1; - break; - case 'k': /* session id */ - if (pi->session_id) - free(pi->session_id); - pi->session_id = strndup(optarg, MAX_STRLEN); - break; - - case 'l': /* license path */ - if (pi->license_path) - free(pi->license_path); - pi->license_path = strndup(optarg, MAX_STRLEN); - break; - - case 'i': /* install */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'i'; - pi->request_type = PKGMGR_REQ_INSTALL; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - DBG("option is [i] pkgid[%s]", pi->pkgmgr_info); - if (pi->pkgmgr_info && strlen(pi->pkgmgr_info) == 0) { - free(pi->pkgmgr_info); - pi->pkgmgr_info = NULL; - } else { - mode = 'i'; - } - break; - - case 'e': /* install */ - if (pi->tep_path) - free(pi->tep_path); - pi->tep_path = strndup(optarg, MAX_STRLEN); - pi->is_tep_included = 1; - DBG("option is [e] tep_path[%s]", pi->tep_path); - break; - - case 'M': /* install */ - if (strcmp(optarg, "tep_move") == 0) - pi->tep_move = 1; - else - pi->tep_move = 0; - DBG("option is [M] tep_move[%d]", pi->tep_move); - break; - - case 'd': /* uninstall */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'd'; - pi->request_type = PKGMGR_REQ_UNINSTALL; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - - case 'c': /* clear */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'c'; - pi->request_type = PKGMGR_REQ_CLEAR; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'm': /* move */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'm'; - pi->request_type = PKGMGR_REQ_MOVE; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'r': /* reinstall */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'r'; - pi->request_type = PKGMGR_REQ_REINSTALL; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 't': /* move type*/ - pi->move_type = atoi(optarg); - break; - - case 'p': /* caller pkgid*/ - if (pi->caller_pkgid) - free(pi->caller_pkgid); - pi->caller_pkgid = strndup(optarg, MAX_STRLEN); - - break; - - case 's': /* smack */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 's'; - pi->request_type = PKGMGR_REQ_SMACK; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'o': /* optional data*/ - pi->optional_data = strndup(optarg, MAX_STRLEN); - break; - - case 'y': /* pkgid for direct manifest installation */ - mode = 'y'; - pi->request_type = PKGMGR_REQ_MANIFEST_DIRECT_INSTALL; - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'w': /* pkgid for mount installation */ - mode = 'w'; - pi->request_type = PKGMGR_REQ_MOUNT_INSTALL; - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'b': /* recovery */ - if (mode) { - r = -EINVAL; - goto RET; - } - mode = 'b'; - pi->request_type = PKGMGR_REQ_RECOVER; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'D': /* disable pkg */ - pi->request_type = PKGMGR_REQ_DISABLE_PKG; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'A': /* enable pkg */ - pi->request_type = PKGMGR_REQ_ENABLE_PKG; - if (pi->pkgmgr_info) - free(pi->pkgmgr_info); - pi->pkgmgr_info = strndup(optarg, MAX_STRLEN); - __parse_multiple_pkgs(pi, argc, argv); - break; - - case 'u': /* uid */ - g_target_uid = (uid_t)atoi(optarg); - pi->target_uid = (uid_t)atoi(optarg); - break; - - case 'G': /* debug mode */ - pi->debug_mode = 1; - g_debug_mode = 1; - break; - - case 'S': /* skip optimization */ - pi->skip_optimization = 1; - g_skip_optimization = 1; - break; - - /* Otherwise */ - case '?': /* Not an option */ - break; - - case ':': /* */ - break; - - } - } - - /* if target user is not set, set as tizenglobalapp user */ - if (pi->target_uid == 0) { - pi->target_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); - g_target_uid = pi->target_uid; - } - RET: - return r; -} - -API int pkgmgr_installer_get_request_type(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->request_type; -} - -API uid_t pkgmgr_installer_get_uid(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->target_uid; -} - -API const char *pkgmgr_installer_get_request_info(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->pkgmgr_info; -} - -API const char *pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi, - int at) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return (const char *)g_list_nth_data(pi->pkgs, at); -} - -API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return g_list_length(pi->pkgs); -} - -API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->tep_path; -} - -API int pkgmgr_installer_get_tep_move_type(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->tep_move; -} - -API const char *pkgmgr_installer_get_session_id(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->session_id; -} - -API const char *pkgmgr_installer_get_license_path(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->license_path; -} - -API const char *pkgmgr_installer_get_optional_data(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->optional_data; -} - -API int pkgmgr_installer_is_quiet(pkgmgr_installer *pi) -{ - return 1; -} - -API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->move_type; -} - -API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->caller_pkgid; -} - -API int pkgmgr_installer_get_is_preload(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->is_preload; -} - -API int pkgmgr_installer_get_force_removal(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->force_removal; -} - -API int pkgmgr_installer_get_is_preload_rw(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->is_preload_rw; -} - -API int pkgmgr_installer_get_no_removal(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->no_removal; -} - -API int pkgmgr_installer_get_keep_rwdata(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->keep_rwdata; -} - -API int pkgmgr_installer_get_partial_rw(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->partial_rw; -} - -API int pkgmgr_installer_get_debug_mode(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->debug_mode; -} - -API int pkgmgr_installer_get_skip_check_reference(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->skip_check_reference; -} - -API int pkgmgr_installer_get_skip_optimization(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->skip_optimization; -} - -API int pkgmgr_installer_get_recovery_cleanup(pkgmgr_installer *pi) -{ - CHK_PI_RET(PKGMGR_REQ_INVALID); - return pi->recovery_cleanup; -} - -API int pkgmgr_installer_send_app_uninstall_signal(pkgmgr_installer *pi, - const char *pkg_type, - const char *pkgid, - const char *val) -{ - int ret = 0; - ret = __send_signal_for_event(pi, pkg_type, pkgid, NULL, - PKGMGR_INSTALLER_APPID_KEY_STR, val); - return ret; -} - -API int pkgmgr_installer_send_app_uninstall_signal_for_uid( - pkgmgr_installer *pi, uid_t uid, const char *pkg_type, - const char *pkgid, const char *val) -{ - int ret = 0; - ret = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, NULL, - PKGMGR_INSTALLER_APPID_KEY_STR, val); - return ret; -} - -API int pkgmgr_installer_set_uid(pkgmgr_installer *pi, uid_t uid) -{ - if (pi == NULL) - return -1; - - pi->target_uid = uid; - g_target_uid = pi->target_uid; - - return 0; -} - -API int -pkgmgr_installer_send_app_signal(pkgmgr_installer *pi, - const char *pkg_type, - const char *pkgid, - const char *appid, - const char *key, const char *val) -{ - int r = 0; - - if (!pi->conn) { - ERR("connection is NULL"); - return -1; - } - - r = __send_signal_for_event(pi, pkg_type, pkgid, appid, key, val); - - return r; -} - -API int -pkgmgr_installer_send_signal(pkgmgr_installer *pi, - const char *pkg_type, - const char *pkgid, - const char *key, const char *val) -{ - int r = 0; - - if (!pi->conn) { - ERR("connection is NULL"); - return -1; - } - - r = __send_signal_for_event(pi, pkg_type, pkgid, NULL, key, val); - - return r; -} - -API int pkgmgr_installer_send_app_signal_for_uid(pkgmgr_installer *pi, - uid_t uid, const char *pkg_type, const char *pkgid, - const char *appid, const char *key, const char *val) -{ - int r = 0; - - if (!pi->conn) { - ERR("connection is NULL"); - return -1; - } - - r = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, appid, - key, val); - - return r; -} - -API int pkgmgr_installer_send_signal_for_uid(pkgmgr_installer *pi, - uid_t uid, const char *pkg_type, const char *pkgid, - const char *key, const char *val) -{ - int r = 0; - - if (!pi->conn) { - ERR("connection is NULL"); - return -1; - } - - r = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, NULL, - key, val); - - return r; -} - -API int pkgmgr_installer_set_request_type(pkgmgr_installer *pi, int request_type) -{ - if (pi == NULL) - return -1; - - pi->request_type = request_type; - return 0; -} - -API int pkgmgr_installer_set_session_id(pkgmgr_installer *pi, const char *session_id) -{ - if (pi == NULL || session_id == NULL) - return -1; - - pi->session_id = strndup(session_id, MAX_STRLEN); - return 0; -} - -API int pkgmgr_installer_create_certinfo_set_handle(pkgmgr_instcertinfo_h *handle) -{ - int ret = 0; - ret = pkgmgrinfo_create_certinfo_set_handle(handle); - return ret; -} - -API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle, pkgmgr_instcert_type cert_type, char *cert_value) -{ - int ret = 0; - ret = pkgmgrinfo_set_cert_value(handle, cert_type, cert_value); - return ret; -} - -API int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle, uid_t uid) -{ - int ret = 0; - ret = pkgmgrinfo_save_certinfo(pkgid, handle, uid); - return ret; -} - -API int pkgmgr_installer_destroy_certinfo_set_handle(pkgmgr_instcertinfo_h handle) -{ - int ret = 0; - ret = pkgmgrinfo_destroy_certinfo_set_handle(handle); - return ret; -} - -API int pkgmgr_installer_delete_certinfo(const char *pkgid) -{ - int ret = 0; - ret = pkgmgrinfo_delete_certinfo(pkgid); - return ret; -} - -API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level) -{ - g_privilege_level = level; - - return 0; -} - -API int pkgmgr_installer_info_get_target_uid(uid_t *uid) -{ - *uid = g_target_uid; - - return 0; -} - -API int pkgmgr_installer_info_get_privilege_level(pkgmgr_privilege_level *level) -{ - *level = g_privilege_level; - - return 0; -} - -API int pkgmgr_installer_info_get_debug_mode(int *debug_mode) -{ - *debug_mode = g_debug_mode; - return 0; -} - -API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization) -{ - *skip_optimization = g_skip_optimization; - return 0; -} - -#define CASE_TO_STR(ERRCODE) case ERRCODE: return ERRCODE##_STR -API const char *pkgmgr_installer_error_to_string(int error_code) -{ - switch (error_code) { - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CERT_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ERROR); - CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OK); - default: - return PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR_STR; - } -} - -API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi, - const char *pkgid, const char *pkg_type) -{ - pkg_signal_info *info; - if (!pi || !pkgid || !pkg_type) { - ERR("invalid argument"); - return -1; - } - - info = calloc(1, sizeof(pkg_signal_info)); - if (!info) { - ERR("out of memory"); - return -1; - } - - info->pkgid = strdup(pkgid); - info->pkg_type = strdup(pkg_type); - if (!info->pkgid || !info->pkg_type) { - ERR("out of memory"); - free(info->pkgid); - free(info->pkg_type); - free(info); - return -1; - } - g_hash_table_insert(pi->pkg_list, (gpointer)info->pkgid, (gpointer)info); - - return 0; -} - -static void __build_multi_signal(gpointer key, gpointer value, - gpointer user_data) -{ - GVariantBuilder *builder = (GVariantBuilder *)user_data; - pkg_signal_info *info = (pkg_signal_info *)value; - - g_variant_builder_add(builder, "(sss)", info->pkgid, "", info->pkg_type); -} - -API int pkgmgr_installer_send_signals(pkgmgr_installer *pi, - const char *key, const char *val) -{ - char *sid; - const char *signal_name; - GError *err = NULL; - GVariantBuilder *builder; - - if (!pi || !key || !val) { - ERR("invalid argument"); - return -1; - } - - sid = pi->session_id; - if (!sid) - sid = ""; - - signal_name = __get_signal_name(pi, key, ""); - if (!signal_name) { - ERR("unknown signal type"); - return -1; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)")); - g_hash_table_foreach(pi->pkg_list, __build_multi_signal, builder); - if (g_dbus_connection_emit_signal(pi->conn, NULL, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, - PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name, - g_variant_new("(usa(sss)ss)", - pi->target_uid, sid, builder, key, - val), &err) != TRUE) { - ERR("failed to send dbus signal"); - if (err) { - ERR("err: %s", err->message); - g_error_free(err); - } - g_variant_builder_unref(builder); - return -1; - } - g_variant_builder_unref(builder); - - return 0; -} - -API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid, - const char *key, const char *val) -{ - char *sid; - size_t data_len; - size_t name_size; - GVariant *gv; - GVariantBuilder *builder; - gsize gv_len; - gpointer gv_data; - void *data; - void *ptr; - const char *signal_name; - - if (!pi || !pi->conn) { - ERR("connection is NULL"); - return -1; - } - - sid = pi->session_id; - if (!sid) - sid = ""; - - data_len = sizeof(size_t) + sizeof(gsize); - - /* including null byte */ - signal_name = __get_signal_name(pi, key, ""); - if (!signal_name) { - ERR("unknown signal type"); - return -1; - } - name_size = strlen(signal_name) + 1; - data_len += name_size; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)")); - g_hash_table_foreach(pi->pkg_list, __build_multi_signal, builder); - - gv = g_variant_new("(usa(sss)ss)", uid, sid, builder, key, val); - g_variant_builder_unref(builder); - if (gv == NULL) { - ERR("failed to create GVariant instance"); - return -1; - } - - gv_len = g_variant_get_size(gv); - gv_data = g_malloc(gv_len); - g_variant_store(gv, gv_data); - g_variant_unref(gv); - data_len += gv_len; - - data = malloc(data_len); - if (data == NULL) { - ERR("out of memory"); - g_free(gv_data); - return -1; - } - ptr = data; - memcpy(ptr, &name_size, sizeof(size_t)); - ptr += sizeof(size_t); - memcpy(ptr, &gv_len, sizeof(gsize)); - ptr += sizeof(gsize); - memcpy(ptr, signal_name, name_size); - ptr += name_size; - memcpy(ptr, gv_data, gv_len); - g_free(gv_data); - - if (__send_signal_to_agent(uid, data, data_len)) { - ERR("failed to send signal to agent"); - free(data); - return -1; - } - - free(data); - - return 0; -} - -API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) { - if (pi == NULL) - return -1; - - pi->is_upgrade = is_upgrade; - return 0; -} - -static GVariant *__get_gvariant_from_event_info(pkgmgr_res_event_info *event_info) -{ - pkgmgr_res_event_info_t *info = event_info; - GVariantBuilder *builder; - GVariant *result; - GList *path_states; - res_event_path_state_t *path_state; - - builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)")); - if (builder == NULL) { - ERR("out of memory"); - return NULL; - } - - for (path_states = info->path_states; path_states != NULL; - path_states = path_states->next) { - path_state = (res_event_path_state_t *)path_states->data; - g_variant_builder_add(builder, "(si)", - path_state->path, path_state->state); - } - - result = g_variant_new("(ia(si))", info->error_code, builder); - g_variant_builder_unref(builder); - - if (result == NULL) { - ERR("Fail to create extra data"); - return NULL; - } - - return result; -} - -API int pkgmgr_installer_send_res_signal(pkgmgr_installer *pi, - const char *pkgid, const char *status, - pkgmgr_res_event_info *event_info) -{ - char *sid; - const char *signal_name; - GError *err = NULL; - GVariant *extra_param; - - if (!pi || !pkgid || !status) { - ERR("invalid argument"); - return -1; - } - - sid = pi->session_id; - if (!sid) - sid = ""; - - signal_name = __get_signal_name(pi, "", ""); - if (!signal_name) { - ERR("unknown signal type"); - return -1; - } - - extra_param = __get_gvariant_from_event_info(event_info); - if (extra_param == NULL) { - ERR("Fail to get extra parameter"); - return -1; - } - - if (g_dbus_connection_emit_signal(pi->conn, NULL, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, - PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name, - g_variant_new("(usssv)", pi->target_uid, sid, - pkgid, status, extra_param), - &err) != TRUE) { - ERR("failed to send dbus signal"); - if (err) { - ERR("err: %s", err->message); - g_error_free(err); - } - return -1; - } - - return 0; -} - -API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi, - uid_t uid, const char *pkgid, const char *status, - pkgmgr_res_event_info *event_info) -{ - char *sid; - size_t data_len; - size_t name_size; - GVariant *gv; - gsize gv_len; - gpointer gv_data; - void *data; - void *ptr; - const char *signal_name; - GVariant *extra_param; - - if (!pi || !pi->conn) { - ERR("connection is NULL"); - return -1; - } - - sid = pi->session_id; - if (!sid) - sid = ""; - - data_len = sizeof(size_t) + sizeof(gsize); - - /* including null byte */ - signal_name = __get_signal_name(pi, "", ""); - if (!signal_name) { - ERR("unknown signal type"); - return -1; - } - name_size = strlen(signal_name) + 1; - data_len += name_size; - - extra_param = __get_gvariant_from_event_info(event_info); - if (extra_param == NULL) { - ERR("Fail to get extra parameter"); - return -1; - } - - gv = g_variant_new("(usssv)", pi->target_uid, sid, - pkgid, status, extra_param); - if (gv == NULL) { - ERR("failed to create GVariant instance"); - return -1; - } - - gv_len = g_variant_get_size(gv); - gv_data = g_malloc(gv_len); - g_variant_store(gv, gv_data); - g_variant_unref(gv); - data_len += gv_len; - - data = malloc(data_len); - if (data == NULL) { - ERR("out of memory"); - g_free(gv_data); - return -1; - } - ptr = data; - memcpy(ptr, &name_size, sizeof(size_t)); - ptr += sizeof(size_t); - memcpy(ptr, &gv_len, sizeof(gsize)); - ptr += sizeof(gsize); - memcpy(ptr, signal_name, name_size); - ptr += name_size; - memcpy(ptr, gv_data, gv_len); - g_free(gv_data); - - if (__send_signal_to_agent(uid, data, data_len)) { - ERR("failed to send signal to agent"); - free(data); - return -1; - } - - free(data); - - return 0; -} diff --git a/installer/pkgmgr_installer_config.h b/installer/pkgmgr_installer_config.h deleted file mode 100644 index 320620b..0000000 --- a/installer/pkgmgr_installer_config.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, - * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __PACKAGE_INSTALLER_CONFIG_H__ -#define __PACKAGE_INSTALLER_CONFIG_H__ - -#define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr" -#define PKGMGR_DBUS_INTERFACE "org.tizen.pkgmgr" -#define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr" - -#define PKGMGR_INSTALLER_DBUS_INTERFACE "org.tizen.pkgmgr.signal" -#define PKGMGR_INSTALLER_DBUS_OBJECT_PATH "/org/tizen/pkgmgr/signal" - -#endif /* __PACKAGE_INSTALLER_CONFIG_H__ */ diff --git a/installer/pkgmgr_installer_signal_agent.c b/installer/pkgmgr_installer_signal_agent.c deleted file mode 100644 index 19c5b44..0000000 --- a/installer/pkgmgr_installer_signal_agent.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#define _GNU_SOURCE - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <sys/un.h> -#include <linux/limits.h> -#include <pwd.h> - -#include <glib.h> -#include <glib-unix.h> -#include <gio/gio.h> -#include <systemd/sd-daemon.h> - -#include <dlog.h> - -#include "pkgmgr_installer_config.h" -#include "pkgmgr_installer_type.h" - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "PKGMGR_INSTALLER_SIGNAL_AGENT" - -#define BUFMAX 4096 -#define PWBUFSIZE sysconf(_SC_GETPW_R_SIZE_MAX) -#define APPFW_USERNAME "app_fw" - -static int server_fd = -1; -static GMainLoop *loop; -static guint sid; -static guint tid; -static GDBusConnection *conn; - -static int __create_server_socket(const char *path) -{ - int r; - int fd; - struct sockaddr_un sa; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd == -1) { - LOGE("socket create failed: %d", errno); - return -1; - } - - memset(&sa, 0, sizeof(sa)); - sa.sun_family = AF_UNIX; - snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", path); - - r = unlink(sa.sun_path); - if (r == -1 && errno != ENOENT) { - LOGE("unlink(%s) failed: %d", sa.sun_path, errno); - close(fd); - return -1; - } - - r = bind(fd, (struct sockaddr *)&sa, sizeof(sa)); - if (r == -1) { - LOGE("bind(%s) failed: %d", sa.sun_path, errno); - close(fd); - return -1; - } - - r = chmod(sa.sun_path, 0660); - if (r == -1) - LOGW("chmod(%s) failed: %d", sa.sun_path, errno); - - r = listen(fd, SOMAXCONN); - if (r == -1) { - LOGE("listen(%s) failed: %d", sa.sun_path, errno); - close(fd); - return -1; - } - - return fd; -} - -static int __get_server_socket(const char *path) -{ - int i; - int n; - int r; - int fd = -1; - - n = sd_listen_fds(0); - if (n < 0) { - LOGE("sd_listen_fds: %d", n); - return -1; - } else if (n == 0) { - return __create_server_socket(path); - } - - for (i = SD_LISTEN_FDS_START; i < SD_LISTEN_FDS_START + n; i++) { - r = sd_is_socket_unix(i, SOCK_STREAM, -1, path, 0); - if (r > 0) { - fd = i; - break; - } - } - - if (fd == -1) { - LOGE("socket is not passed, create server socket"); - return __create_server_socket(path); - } - - return fd; -} - -static void __emit_signal(const char *name, GVariant *gv) -{ - GError *err = NULL; - - if (g_dbus_connection_emit_signal(conn, NULL, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, - PKGMGR_INSTALLER_DBUS_INTERFACE, - name, gv, &err) != TRUE) { - LOGE("g_dbus_connection_emit_signal failed: %s", err->message); - g_error_free(err); - } -} - -static gboolean __quit(gpointer user_data) -{ - g_main_loop_quit(loop); - return FALSE; -} - -static int __check_authority(int fd) -{ - int r; - struct ucred cr; - socklen_t len; - struct passwd pwd; - struct passwd *pwd_r; - char buf[PWBUFSIZE]; - - len = sizeof(struct ucred); - r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len); - if (r != 0) { - LOGE("getsockopt failed: %d", errno); - return -1; - } - - /* allow root user */ - if (cr.uid == 0) - return 0; - - r = getpwuid_r(cr.uid, &pwd, buf, sizeof(buf), &pwd_r); - if (r != 0 || pwd_r == NULL) { - LOGE("getpwuid failed: %d", r); - return -1; - } - - /* only app_fw user can send signal to agent */ - if (strcmp(pwd_r->pw_name, APPFW_USERNAME) != 0) { - LOGE("unauthorized client"); - return -1; - } - - return 0; -} - -/** - * packet format: - * +----------------+-------------+-----------+-------------------+ - * |signal name size|GVariant size|signal name|serialized GVariant| - * +----------------+-------------+-----------+-------------------+ - */ -static gboolean __handle_signal(gint fd, GIOCondition cond, gpointer user_data) -{ - int r; - unsigned char buf[BUFMAX]; - int clifd; - struct sockaddr_un sa; - socklen_t s = sizeof(sa); - size_t type_len; - char *type_name; - gsize data_len; - gpointer data; - GVariant *gv; - - clifd = accept(fd, (struct sockaddr *)&sa, &s); - if (clifd == -1) { - LOGE("accept failed: %d", errno); - return FALSE; - } - - if (__check_authority(clifd)) { - close(clifd); - return TRUE; - } - - r = recv(clifd, buf, sizeof(size_t) + sizeof(gsize), 0); - if (r < 0) { - LOGE("recv failed: %d", errno); - close(clifd); - return FALSE; - } else if (r == 0) { - LOGE("client fd already closed"); - close(clifd); - return FALSE; - } - - memcpy(&type_len, buf, sizeof(size_t)); - memcpy(&data_len, buf + sizeof(size_t), sizeof(gsize)); - - if (type_len > BUFMAX || data_len > BUFMAX || - (type_len + data_len) > BUFMAX) { - LOGE("received size is too large: %zu %zu", type_len, data_len); - close(clifd); - return FALSE; - } - - r = recv(clifd, buf, type_len + data_len, 0); - if (r < 0) { - LOGE("recv failed: %d", errno); - close(clifd); - return FALSE; - } else if (r == 0) { - LOGE("client fd already closed"); - close(clifd); - return FALSE; - } - - if (type_len == 0) { - LOGE("invalid type_len"); - close(clifd); - return FALSE; - } - - /* get signal name (including terminating null byte) */ - type_name = malloc(type_len); - memcpy(type_name, buf, type_len); - - /* get data */ - data = malloc(data_len); - memcpy(data, buf + type_len, data_len); - - /* floating type GVariant instance */ - if (!strcmp(type_name, PKGMGR_INSTALLER_RES_COPY_EVENT_STR) || - !strcmp(type_name, PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR) || - !strcmp(type_name, PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR) || - !strcmp(type_name, PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR)) { - gv = g_variant_new_from_data(G_VARIANT_TYPE("(usssv)"), - data, data_len, TRUE, NULL, NULL); - } else { - gv = g_variant_new_from_data(G_VARIANT_TYPE("(usa(sss)ss)"), - data, data_len, TRUE, NULL, NULL); - } - __emit_signal(type_name, gv); - - free(data); - free(type_name); - close(clifd); - - /* renew timeout */ - g_source_remove(tid); - tid = g_timeout_add_seconds(10, __quit, NULL); - - return TRUE; -} - -static int __init(void) -{ - char path[PATH_MAX]; - GError *err = NULL; - - snprintf(path, sizeof(path), "/run/pkgmgr/agent/%d", getuid()); - server_fd = __get_server_socket(path); - if (server_fd < 0) { - LOGE("server init failed"); - return -1; - } - - conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err); - if (conn == NULL) { - LOGE("g_bus_get_sync failed: %s", err->message); - g_error_free(err); - close(server_fd); - return -1; - } - - loop = g_main_loop_new(NULL, FALSE); - sid = g_unix_fd_add(server_fd, G_IO_IN, __handle_signal, NULL); - tid = g_timeout_add_seconds(10, __quit, NULL); - - return 0; -} - -static void __fini(void) -{ - if (sid > 0) - g_source_remove(sid); - if (loop) - g_main_loop_unref(loop); - if (conn) - g_object_unref(conn); - if (server_fd > 0) - close(server_fd); -} - -int main(int argc, char *argv[]) -{ - int r; - - r = __init(); - if (r < 0) - return -1; - - g_main_loop_run(loop); - - __fini(); - - return 0; -} diff --git a/installer/src/api_stub.cc b/installer/src/api_stub.cc new file mode 100644 index 0000000..d975965 --- /dev/null +++ b/installer/src/api_stub.cc @@ -0,0 +1,364 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "pkgmgr_installer.h" + +#include <unistd.h> + +#include "control.hh" + +#ifdef API +#undef API +#endif +#define API __attribute__ ((visibility("default"))) + +API pkgmgr_installer* pkgmgr_installer_new() { + return new pkgmgr::installer::Control(); +} + +API pkgmgr_installer* pkgmgr_installer_offline_new() { + return new pkgmgr::installer::Control(true); +} + +API int pkgmgr_installer_free(pkgmgr_installer* pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + delete cls; + return 0; +} + +API int pkgmgr_installer_receive_request(pkgmgr_installer *pi, + const int argc, char **argv) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + return cls->SetRequestFromArgv(argc, argv); +} + +API int pkgmgr_installer_get_request_type(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->GetRequestType(); +} + +API uid_t pkgmgr_installer_get_uid(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->GetUid(); +} + +API const char* pkgmgr_installer_get_request_info(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetRequestInfo().c_str(); +} + +API const char* pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi, + int at) { + //TODO + return nullptr; +} + +API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi) { + //TODO + return 0; +} + +API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetTepPath().c_str(); +} + +API int pkgmgr_installer_get_tep_move_type(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsTepMove() ? 1 : 0; +} + +API const char* pkgmgr_installer_get_session_id(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetSessionId().c_str(); +} + +API const char* pkgmgr_installer_get_license_path(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetLicensePath().c_str(); +} + +API const char* pkgmgr_installer_get_optional_data(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetOptionalData().c_str(); +} + +API int pkgmgr_installer_is_quiet(pkgmgr_installer *pi) { + return 1; +} + +API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->GetMoveType(); +} + +API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return nullptr; + return cls->GetRequest()->GetCallerPkgid().c_str(); +} + +API int pkgmgr_installer_get_is_preload(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsPreload() ? 1 : 0; +} + +API int pkgmgr_installer_get_force_removal(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsForceRemoval() ? 1 : 0; +} + +API int pkgmgr_installer_get_is_preload_rw(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsPreloadRw() ? 1 : 0; +} + +API int pkgmgr_installer_get_no_removal(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsNoRemoval() ? 1 : 0; +} + +API int pkgmgr_installer_get_keep_rwdata(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsKeepRwData() ? 1 : 0; +} + +API int pkgmgr_installer_get_partial_rw(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsPartialRw() ? 1 : 0; +} + +API int pkgmgr_installer_get_debug_mode(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsDebugMode() ? 1 : 0; +} + +API int pkgmgr_installer_get_skip_check_reference(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsSkipCheckReference() ? 1 : 0; +} + +API int pkgmgr_installer_get_skip_optimization(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsSkipOptimization() ? 1 : 0; +} + +API int pkgmgr_installer_get_recovery_cleanup(pkgmgr_installer *pi) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return PKGMGR_REQ_INVALID; + return cls->GetRequest()->IsRecoveryCleanup() ? 1 : 0; +} + +API int pkgmgr_installer_send_app_uninstall_signal(pkgmgr_installer *pi, + const char *pkg_type, const char *pkgid, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_app_uninstall_signal_for_uid( + pkgmgr_installer *pi, uid_t uid, const char *pkg_type, + const char *pkgid, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_uid(pkgmgr_installer *pi, uid_t uid) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return -1; + cls->GetRequest()->SetUid(uid); + return 0; +} + +API int pkgmgr_installer_send_app_signal(pkgmgr_installer *pi, + const char *pkg_type, const char *pkgid, const char *appid, + const char *key, const char *val) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return -1; + return cls->SendSignal(pkg_type, pkgid, appid, key, val); +} + +API int pkgmgr_installer_send_signal(pkgmgr_installer *pi, + const char *pkg_type, const char *pkgid, const char *key, + const char *val) { + auto* cls = static_cast<pkgmgr::installer::Control*>(pi); + if (!cls->GetRequest()) + return -1; + return cls->SendSignal(pkg_type, pkgid, "", key, val); +} + +API int pkgmgr_installer_send_app_signal_for_uid(pkgmgr_installer *pi, + uid_t uid, const char *pkg_type, const char *pkgid, + const char *appid, const char *key, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_signal_for_uid(pkgmgr_installer *pi, + uid_t uid, const char *pkg_type, const char *pkgid, + const char *key, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_request_type(pkgmgr_installer *pi, + int request_type) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_session_id(pkgmgr_installer *pi, + const char *session_id) { + //TODO + return 0; +} + +API int pkgmgr_installer_create_certinfo_set_handle( + pkgmgr_instcertinfo_h *handle) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle, + pkgmgr_instcert_type cert_type, char *cert_value) { + //TODO + return 0; +} + +API int pkgmgr_installer_save_certinfo(const char *pkgid, + pkgmgr_instcertinfo_h handle, uid_t uid) { + //TODO + return 0; +} + +API int pkgmgr_installer_destroy_certinfo_set_handle( + pkgmgr_instcertinfo_h handle) { + //TODO + return 0; +} + +API int pkgmgr_installer_delete_certinfo(const char *pkgid) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level) { + //TODO + return 0; +} + +API int pkgmgr_installer_info_get_target_uid(uid_t *uid) { + //TODO + return 0; +} + +API int pkgmgr_installer_info_get_privilege_level( + pkgmgr_privilege_level *level) { + //TODO + return 0; +} + +API int pkgmgr_installer_info_get_debug_mode(int *debug_mode) { + //TODO + return 0; +} + +API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization) { + //TODO + return 0; +} + +API const char* pkgmgr_installer_error_to_string(int error_code) { + //TODO + return nullptr; +} + +API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi, + const char *pkgid, const char *pkg_type) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_signals(pkgmgr_installer *pi, + const char *key, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid, + const char *key, const char *val) { + //TODO + return 0; +} + +API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_res_signal(pkgmgr_installer *pi, + const char *pkgid, const char *status, + pkgmgr_res_event_info *event_info) { + //TODO + return 0; +} + +API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi, + uid_t uid, const char *pkgid, const char *status, + pkgmgr_res_event_info *event_info) { + //TODO + return 0; +} diff --git a/installer/src/control.cc b/installer/src/control.cc new file mode 100644 index 0000000..d094c6a --- /dev/null +++ b/installer/src/control.cc @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "control.hh" + +#include <getopt.h> + +#include "pkgmgr_installer.h" +#include "pkgmgr_installer_debug.h" + +namespace { + +constexpr int OPTVAL_PRELOAD = 1000; +constexpr int OPTVAL_FORCE_REMOVAL = 1001; +constexpr int OPTVAL_PRELOAD_RW = 1002; +constexpr int OPTVAL_NO_REMOVAL = 1003; +constexpr int OPTVAL_KEEP_RWDATA = 1004; +constexpr int OPTVAL_PARTIAL_RW = 1005; +constexpr int OPTVAL_MIGRATE_EXTIMG = 1006; +constexpr int OPTVAL_SKIP_CHECK_REFERENCE = 1007; +constexpr int OPTVAL_RECOVER_DB = 1008; +constexpr int OPTVAL_RECOVERY_CLEANUP = 1009; + +constexpr const char short_opts[] = "k:l:i:d:c:m:t:o:r:p:s:b:e:M:y:u:w:D:A:qGS"; +constexpr const struct option long_opts[] = { + { "session-id", 1, nullptr, 'k' }, + { "license-path", 1, nullptr, 'l' }, + { "install", 1, nullptr, 'i' }, + { "uninstall", 1, nullptr, 'd' }, + { "clear", 1, nullptr, 'c' }, + { "move", 1, nullptr, 'm' }, + { "move-type", 1, nullptr, 't' }, + { "optional-data", 0, nullptr, 'o' }, + { "reinstall", 0, nullptr, 'r' }, + { "caller-pkgid", 1, nullptr, 'p' }, + { "tep-path", 1, nullptr, 'e' }, + { "tep-move", 1, nullptr, 'M' }, + { "smack", 1, nullptr, 's' }, + { "manifest-direct-install", 1, nullptr, 'y' }, + { "mount-install", 1, nullptr, 'w' }, + { "recovery", 1, nullptr, 'b' }, + { "debug-mode", 0, nullptr, 'G' }, + { "skip-optimization", 0, nullptr, 'S' }, + { "preload", 0, nullptr, OPTVAL_PRELOAD }, + { "force-remove", 0, nullptr, OPTVAL_FORCE_REMOVAL }, + { "preload-rw", 0, nullptr, OPTVAL_PRELOAD_RW }, + { "no-remove", 0, nullptr, OPTVAL_NO_REMOVAL }, + { "keep-rwdata", 0, nullptr, OPTVAL_KEEP_RWDATA }, + { "partial-rw", 0, nullptr, OPTVAL_PARTIAL_RW }, + { "migrate-extimg", 1, nullptr, OPTVAL_MIGRATE_EXTIMG }, + { "skip-check-reference", 0, nullptr, OPTVAL_SKIP_CHECK_REFERENCE }, + { "recover-db", 1, nullptr, OPTVAL_RECOVER_DB }, + { "recovery-cleanup", 0, nullptr, OPTVAL_RECOVERY_CLEANUP }, + { 0, 0, 0, 0 } +}; + +} + +namespace pkgmgr { +namespace installer { + +Control::Control(bool offline) { + if (!offline) { + signal_.reset(new pkg_group::PkgSignal("", true)); + } + + option_map_[OPTVAL_PRELOAD] = [](const std::unique_ptr<Request>& req) { + req->is_preload_ = true; + _D("preload request [%d]", req->is_preload_); + return 0; + }; + + option_map_[OPTVAL_FORCE_REMOVAL] = [](const std::unique_ptr<Request>& req) { + req->force_removal_ = true; + _D("force-remove request [%d]", req->force_removal_); + return 0; + }; + + option_map_[OPTVAL_PRELOAD_RW] = [](const std::unique_ptr<Request>& req) { + req->is_preload_rw_ = true; + _D("preload-rw request [%d]", req->is_preload_rw_); + return 0; + }; + + option_map_[OPTVAL_NO_REMOVAL] = [](const std::unique_ptr<Request>& req) { + req->no_removal_ = true; + _D("no-remove request [%d]", req->no_removal_); + return 0; + }; + + option_map_[OPTVAL_KEEP_RWDATA] = [](const std::unique_ptr<Request>& req) { + req->keep_rwdata_ = true; + _D("keep-rwdata request [%d]", req->keep_rwdata_); + return 0; + }; + + option_map_[OPTVAL_PARTIAL_RW] = [](const std::unique_ptr<Request>& req) { + req->partial_rw_ = true; + _D("partial-rw request [%d]", req->partial_rw_); + return 0; + }; + + option_map_[OPTVAL_MIGRATE_EXTIMG] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = OPTVAL_MIGRATE_EXTIMG; + req->request_type_ = PKGMGR_REQ_MIGRATE_EXTIMG; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + _D("legacy extimg migration requested"); + return 0; + }; + + option_map_[OPTVAL_SKIP_CHECK_REFERENCE] = [](const std::unique_ptr<Request>& req) { + req->skip_check_reference_ = true; + return 0; + }; + + option_map_[OPTVAL_RECOVER_DB] = [this](const std::unique_ptr<Request>& req) { + req->request_type_ = PKGMGR_REQ_RECOVER_DB; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_[OPTVAL_RECOVERY_CLEANUP] = [](const std::unique_ptr<Request>& req) { + req->recovery_cleanup_ = true; + return 0; + }; + + option_map_['k'] = [](const std::unique_ptr<Request>& req) { + req->session_id_ = optarg; + return 0; + }; + + option_map_['l'] = [](const std::unique_ptr<Request>& req) { + req->license_path_ = optarg; + return 0; + }; + + option_map_['i'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'i'; + req->request_type_ = PKGMGR_REQ_INSTALL; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + _D("option is [i] pkgid[%s]", req->pkgmgr_info_.c_str()); + return 0; + }; + + option_map_['e'] = [](const std::unique_ptr<Request>& req) { + req->tep_path_ = optarg; + _D("option is [e] tep_path[%s]", req->tep_path_.c_str()); + return 0; + }; + + option_map_['M'] = [](const std::unique_ptr<Request>& req) { + if (strcmp(optarg, "tep_move") == 0) + req->tep_move_ = true; + else + req->tep_move_ = false; + _D("option is [M] tep_move[%d]", req->tep_move_); + return 0; + }; + + option_map_['d'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'd'; + req->request_type_ = PKGMGR_REQ_UNINSTALL; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['c'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'c'; + req->request_type_ = PKGMGR_REQ_CLEAR; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['m'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'm'; + req->request_type_ = PKGMGR_REQ_MOVE; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['r'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'r'; + req->request_type_ = PKGMGR_REQ_REINSTALL; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['t'] = [](const std::unique_ptr<Request>& req) { + req->move_type_ = atoi(optarg); + return 0; + }; + + option_map_['p'] = [](const std::unique_ptr<Request>& req) { + req->caller_pkgid_ = optarg; + return 0; + }; + + option_map_['s'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 's'; + req->request_type_ = PKGMGR_REQ_SMACK; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['o'] = [](const std::unique_ptr<Request>& req) { + req->optional_data_ = optarg; + return 0; + }; + + option_map_['y'] = [this](const std::unique_ptr<Request>& req) { + req->request_type_ = PKGMGR_REQ_MANIFEST_DIRECT_INSTALL; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['w'] = [this](const std::unique_ptr<Request>& req) { + req->request_type_ = PKGMGR_REQ_MOUNT_INSTALL; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['b'] = [this](const std::unique_ptr<Request>& req) { + if (mode_) + return -EINVAL; + mode_ = 'b'; + req->request_type_ = PKGMGR_REQ_RECOVER; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['D'] = [this](const std::unique_ptr<Request>& req) { + req->request_type_ = PKGMGR_REQ_DISABLE_PKG; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['A'] = [this](const std::unique_ptr<Request>& req) { + req->request_type_ = PKGMGR_REQ_ENABLE_PKG; + req->pkgmgr_info_ = optarg; + ParseMultiplePkgs(req); + return 0; + }; + + option_map_['u'] = [](const std::unique_ptr<Request>& req) { + req->target_uid_ = (uid_t)atoi(optarg); + return 0; + }; + + option_map_['G'] = [](const std::unique_ptr<Request>& req) { + req->debug_mode_ = true; + return 0; + }; + + option_map_['S'] = [](const std::unique_ptr<Request>& req) { + req->skip_optimization_ = true; + return 0; + }; +} + +Control::~Control() = default; + +void Control::ParseMultiplePkgs(const std::unique_ptr<Request>& req) { + while ((optind <= argc_) && (*argv_[optind - 1] != '-')) { + req->pkgs_.push_back(argv_[optind - 1]); + optind++; + } + optind--; +} + +const std::unique_ptr<Request>& Control::GetRequest() const { + return request_; +} + +int Control::SendSignal(std::string pkg_type, std::string pkgid, + std::string appid, std::string key, std::string val) { + if (!signal_) { + _E("offline mode"); + return -1; + } + auto& req = GetRequest(); + std::vector<rpc_port::PkgSignal::PkgInfo> pkgs; + pkgs.push_back(rpc_port::PkgSignal::PkgInfo(std::move(pkgid), + std::move(appid), std::move(pkg_type))); + signal_->AsyncResult(req->GetUid(), req->GetSessionId(), std::move(pkgs), + key, val); + return 0; +} + +int Control::SetRequestFromArgv(const int argc, char** argv) { + auto req = std::make_unique<Request>(); + int opt_idx = 0; + optind = 1; + argc_ = argc; + argv_ = argv; + mode_ = 0; + + while (true) { + int c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx); + if (c == -1) + break; + + if (option_map_.find(c) != option_map_.end()) { + int ret = option_map_[c](req); + if (ret < 0) + return ret; + } + } + + request_ = std::move(req); + return 0; +} + +} // namespace installer +} // namespace pkgmgr diff --git a/installer/src/control.hh b/installer/src/control.hh new file mode 100644 index 0000000..de80856 --- /dev/null +++ b/installer/src/control.hh @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef INSTALLER_SRC_CONTROL_H_ +#define INSTALLER_SRC_CONTROL_H_ + +#include <map> +#include <memory> +#include <string> +#include <list> +#include <functional> + +#include "PkgSignal.h" +#include "request.hh" + +namespace pkgmgr { +namespace installer { + +namespace pkg_group = rpc_port::PkgSignal::group; + +class Control { + public: + Control(bool offline = false); + virtual ~Control(); + int SetRequestFromArgv(const int argc, char** argv); + const std::unique_ptr<Request>& GetRequest() const; + int SendSignal(std::string pkg_type, std::string pkgid, + std::string appid, std::string key, std::string val); + + private: + void ParseMultiplePkgs(const std::unique_ptr<Request>& req); + + private: + std::unique_ptr<Request> request_; + std::unique_ptr<pkg_group::PkgSignal> signal_; + std::map<int, std::function<int(const std::unique_ptr<Request>&)>> + option_map_; + int argc_ = 0; + char** argv_ = nullptr; + int mode_ = 0; +}; + +} // namespace installer +} // namespace pkgmgr + +#endif // INSTALLER_SRC_CONTROL_H_
\ No newline at end of file diff --git a/installer/pkgmgr_installer.h b/installer/src/pkgmgr_installer.h index a6848f5..7ecbabe 100644 --- a/installer/pkgmgr_installer.h +++ b/installer/src/pkgmgr_installer.h @@ -43,7 +43,7 @@ extern "C" { /** * pkgmgr_installer is an opaque type for an object */ -typedef struct pkgmgr_installer pkgmgr_installer; +typedef void pkgmgr_installer; typedef void *pkgmgr_instcertinfo_h; /** diff --git a/installer/pkgmgr_installer_debug.h b/installer/src/pkgmgr_installer_debug.h index 26df677..a92a883 100644 --- a/installer/pkgmgr_installer_debug.h +++ b/installer/src/pkgmgr_installer_debug.h @@ -25,16 +25,16 @@ #endif /* LOG_TAG */ #define LOG_TAG "PKGMGR_INSTALLER" -#ifndef ERR -#define ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#ifndef _E +#define _E LOGE #endif -#ifndef DBG -#define DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#ifndef _D +#define _D LOGD #endif -#ifndef INFO -#define INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#ifndef _I +#define _I LOGI #endif #endif /* __PKGMGR_INSTALLER_DEBUG_H__ */ diff --git a/installer/pkgmgr_installer_error.h b/installer/src/pkgmgr_installer_error.h index 7f60c03..7f60c03 100644 --- a/installer/pkgmgr_installer_error.h +++ b/installer/src/pkgmgr_installer_error.h diff --git a/installer/pkgmgr_installer_info.h b/installer/src/pkgmgr_installer_info.h index 2d32446..2d32446 100644 --- a/installer/pkgmgr_installer_info.h +++ b/installer/src/pkgmgr_installer_info.h diff --git a/installer/pkgmgr_installer_type.h b/installer/src/pkgmgr_installer_type.h index 9463fce..9463fce 100644 --- a/installer/pkgmgr_installer_type.h +++ b/installer/src/pkgmgr_installer_type.h diff --git a/installer/src/request.cc b/installer/src/request.cc new file mode 100644 index 0000000..0593291 --- /dev/null +++ b/installer/src/request.cc @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "request.hh" + +#include <unistd.h> + +namespace pkgmgr { +namespace installer { + +Request::Request() { + target_uid_ = getuid(); +} + +Request::~Request() = default; + +int Request::GetRequestType() const { + return request_type_; +} + +int Request::GetMoveType() const { + return move_type_; +} + +void Request::SetUpgrade(bool is_upgrade) { + is_upgrade_ = is_upgrade; +} + +const std::string& Request::GetRequestInfo() const { + return pkgmgr_info_; +} + +const std::string& Request::GetSessionId() const { + return session_id_; +} + +const std::string& Request::GetLicensePath() const { + return license_path_; +} + +const std::string& Request::GetOptionalData() const { + return optional_data_; +} + +const std::string& Request::GetCallerPkgid() const { + return caller_pkgid_; +} + +void Request::SetUid(uid_t uid) { + target_uid_ = uid; +} + +uid_t Request::GetUid() const { + return target_uid_; +} + +const std::string& Request::GetTepPath() const { + return tep_path_; +} + +bool Request::IsTepMove() const { + return tep_move_; +} + +bool Request::IsPreload() const { + return is_preload_; +} + +bool Request::IsForceRemoval() const { + return force_removal_; +} + +bool Request::IsPreloadRw() const { + return is_preload_rw_; +} + +bool Request::IsNoRemoval() const { + return no_removal_; +} + +bool Request::IsKeepRwData() const { + return keep_rwdata_; +} + +bool Request::IsPartialRw() const { + return partial_rw_; +} + +bool Request::IsDebugMode() const { + return debug_mode_; +} + +bool Request::IsSkipCheckReference() const { + return skip_check_reference_; +} + +bool Request::IsSkipOptimization() const { + return skip_optimization_; +} + +bool Request::IsRecoveryCleanup() const { + return recovery_cleanup_; +} + +} // namespace installer +} // namespace pkgmgr diff --git a/installer/src/request.hh b/installer/src/request.hh new file mode 100644 index 0000000..217f561 --- /dev/null +++ b/installer/src/request.hh @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef INSTALLER_SRC_REQUEST_H_ +#define INSTALLER_SRC_REQUEST_H_ + +#include <map> +#include <memory> +#include <string> +#include <list> +#include <vector> + +#include "PkgSignal.h" + +namespace pkgmgr { +namespace installer { + +class Control; +class Request { + public: + Request(); + virtual ~Request(); + + int GetRequestType() const; + int GetMoveType() const; + void SetUpgrade(bool is_upgrade); + const std::string& GetRequestInfo() const; + const std::string& GetSessionId() const; + const std::string& GetLicensePath() const; + const std::string& GetOptionalData() const; + const std::string& GetCallerPkgid() const; + void SetUid(uid_t uid); + uid_t GetUid() const; + const std::string& GetTepPath() const; + bool IsTepMove() const; + bool IsPreload() const; + bool IsForceRemoval() const; + bool IsPreloadRw() const; + bool IsNoRemoval() const; + bool IsKeepRwData() const; + bool IsPartialRw() const; + bool IsDebugMode() const; + bool IsSkipCheckReference() const; + bool IsSkipOptimization() const; + bool IsRecoveryCleanup() const; + + private: + friend class Control; + int request_type_ = 0; + int move_type_ = 0; + bool is_upgrade_ = false; + std::string pkgmgr_info_; + std::string session_id_; + std::string license_path_; + std::string optional_data_; + std::string caller_pkgid_; + uid_t target_uid_ = 0; + std::string tep_path_; + bool tep_move_ = false; + bool is_preload_ = false; + bool force_removal_ = false; + bool is_preload_rw_ = false; + bool no_removal_ = false; + bool keep_rwdata_ = false; + bool partial_rw_ = false; + bool debug_mode_ = false; + bool skip_check_reference_ = false; + bool skip_optimization_ = false; + bool recovery_cleanup_ = false; + std::vector<std::string> pkgs_; +}; + +} // namespace installer +} // namespace pkgmgr + +#endif // INSTALLER_SRC_REQUEST_H_
\ No newline at end of file diff --git a/packaging/pkgmgr-installer-signal-agent.service b/packaging/pkgmgr-installer-signal-agent.service deleted file mode 100644 index 545ff4a..0000000 --- a/packaging/pkgmgr-installer-signal-agent.service +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=Package Manager Installer Signal Agent on User Session - -[Service] -Type=oneshot -ExecStart=/usr/bin/pkgmgr-installer-signal-agent diff --git a/packaging/pkgmgr-installer-signal-agent.socket b/packaging/pkgmgr-installer-signal-agent.socket deleted file mode 100644 index 2e767cd..0000000 --- a/packaging/pkgmgr-installer-signal-agent.socket +++ /dev/null @@ -1,7 +0,0 @@ -[Socket] -ListenStream=/run/pkgmgr/agent/%U -SocketMode=0777 -DirectoryMode=0777 - -[Install] -WantedBy=sockets.target diff --git a/packaging/pkgmgr.changes b/packaging/pkgmgr.changes deleted file mode 100644 index 101d179..0000000 --- a/packaging/pkgmgr.changes +++ /dev/null @@ -1,18 +0,0 @@ -* Tue Jul 02 2013 Junfeng Dong <junfeng.dong@intel.com> accepted/tizen/20130603.181624@c6b4eaa -- Link pkgmgr-info after pkgmgr-parse to fix the build error in mobile. - -* Thu Jun 27 2013 Anas Nashif <anas.nashif@intel.com> accepted/tizen/20130603.181624@3e413f3 -- Spec file clean up, install configs in /etc - -* Mon Jun 03 2013 Anas Nashif <anas.nashif@intel.com> submit/tizen/20130601.183631@fff80e8 -- Fixed build on 64 bit systems - -* Sat Jun 01 2013 Anas Nashif <anas.nashif@intel.com> submit/tizen/20130517.185027@a8c5788 -- Remove license/group placeholders - -* Mon May 20 2013 Rusty Lynch <rusty.lynch@intel.com> accepted/tizen/20130520.103548@a8c5788 -- Fix install of package in a buildroot environment - -* Fri May 17 2013 Anas Nashif <anas.nashif@intel.com> submit/tizen/20130517.044823@933748f -- do not exclude binaries, just delete them - diff --git a/packaging/pkgmgr.conf b/packaging/pkgmgr.conf index c92c823..642a6f1 100644 --- a/packaging/pkgmgr.conf +++ b/packaging/pkgmgr.conf @@ -1,4 +1,4 @@ d /tmp/pkgmgr 1777 root users t /tmp/pkgmgr - - - - security.SMACK64="User::App::Shared" t /tmp/pkgmgr - - - - security.SMACK64TRANSMUTE="TRUE" -d /run/pkgmgr/agent 0777 root users - + diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index 8a55db3..847c11f 100644 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -12,8 +12,6 @@ Source1004: %{name}-installer.manifest Source1005: %{name}-installer-devel.manifest Source1006: %{name}-types-devel.manifest Source1007: %{name}.conf -Source1008: %{name}-installer-signal-agent.service -Source1009: %{name}-installer-signal-agent.socket Requires(post): /usr/sbin/useradd Requires(post): capi-system-info @@ -32,13 +30,29 @@ BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(minizip) +BuildRequires: pkgconfig(rpc-port) +BuildRequires: pkgconfig(capi-appfw-event) +BuildRequires: pkgconfig(gmock) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes +BuildRequires: tidl + +%if 0%{?gcov:1} +BuildRequires: lcov +%endif %description Packager Manager client library package for packaging +%if 0%{?gcov:1} +%package gcov +Summary: Packager Manager library (gcov) +Group: Application Framework/Testing + +%description gcov +Packager Manager library gcov objects +%endif %package client Summary: Package Manager client library develpoment package @@ -86,15 +100,37 @@ Package Manager client types develpoment package for packaging %prep %setup -q cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{SOURCE1005} %{SOURCE1006} . +tidlc -p -l C++ -i ./tidl/PkgMgr.tidl -o PkgMgrProxy +mv PkgMgrProxy.* ./client/src/ +tidlc -g -l C++ -i ./tidl/PkgSignal.tidl -o PkgSignal +cp PkgSignal.* ./client/src/ +mv PkgSignal.* ./installer/src/ %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export FFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} %__make %{?_smp_mflags} +%if 0%{?gcov:1} +mkdir -p gcov-obj +find . -name '*.gcno' -exec cp '{}' gcov-obj ';' +%endif + %install %make_install + +%if 0%{?gcov:1} +mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} +%endif + rm -f %{buildroot}%{_bindir}/pkgmgr_backend_sample rm -f %{buildroot}%{_libdir}/libpkgmgr_backend_lib_sample.so rm -f %{buildroot}%{_libdir}/libpkgmgr_parser_lib_sample.so @@ -102,11 +138,6 @@ rm -f %{buildroot}%{_libdir}/libpkgmgr_parser_lib_sample.so mkdir -p %{buildroot}%{_tmpfilesdir}/ install -m 0644 %{SOURCE1007} %{buildroot}%{_tmpfilesdir}/pkgmgr.conf -mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants -install -m 0644 %{SOURCE1008} %{buildroot}%{_unitdir_user}/pkgmgr-installer-signal-agent.service -install -m 0644 %{SOURCE1009} %{buildroot}%{_unitdir_user}/pkgmgr-installer-signal-agent.socket -ln -sf ../pkgmgr-installer-signal-agent.socket %{buildroot}%{_unitdir_user}/sockets.target.wants/pkgmgr-installer-signal-agent.socket - mkdir -p %{buildroot}%{_sysconfdir}/package-manager/backend mkdir -p %{buildroot}%{_sysconfdir}/package-manager/backendlib mkdir -p %{buildroot}%{_sysconfdir}/opt/upgrade @@ -118,6 +149,14 @@ chmod 755 %{buildroot}%{_sysconfdir}/package-manager/backend/pkgmgr touch %{buildroot}%{_sysconfdir}/package-manager/backend/pkgtool chmod 755 %{buildroot}%{_sysconfdir}/package-manager/backend/pkgtool +%check +export LD_LIBRARY_PATH=../../client +ctest -V + +%if 0%{?gcov:1} +lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info +genhtml %{name}.info -o out --legend --show-details +%endif %fdupes %{buildroot} @@ -196,10 +235,6 @@ rm -rf %{_sysconfdir}/package-manager/pkgmgr-label-initial-image.sh %license LICENSE %defattr(-,root,root,-) %{_libdir}/libpkgmgr_installer.so.* -%{_bindir}/pkgmgr-installer-signal-agent -%{_unitdir_user}/pkgmgr-installer-signal-agent.service -%{_unitdir_user}/pkgmgr-installer-signal-agent.socket -%{_unitdir_user}/sockets.target.wants/pkgmgr-installer-signal-agent.socket %files installer-devel %manifest %{name}-installer-devel.manifest @@ -215,3 +250,8 @@ rm -rf %{_sysconfdir}/package-manager/pkgmgr-label-initial-image.sh %defattr(-,root,root,-) %{_includedir}/package-manager-*.h %{_libdir}/pkgconfig/pkgmgr-types.pc + +%if 0%{?gcov:1} +%files gcov +%{_datadir}/gcov/* +%endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..c90fac8 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(unit_tests) diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt new file mode 100644 index 0000000..d328392 --- /dev/null +++ b/test/unit_tests/CMakeLists.txt @@ -0,0 +1,33 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TESTS_MOCK_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../client/src CLIENT_SRCS) +ADD_EXECUTABLE(${TARGET_PKGMGR_UNIT_TEST} + ${UNIT_TESTS_SRCS} + ${UNIT_TESTS_MOCK_SRCS} + ${CLIENT_SRCS} +) + +TARGET_INCLUDE_DIRECTORIES(${TARGET_PKGMGR_UNIT_TEST} PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/../../client/src/" + "${CMAKE_CURRENT_SOURCE_DIR}/../../clinet/include/" + "${CMAKE_CURRENT_SOURCE_DIR}/../" + "${CMAKE_CURRENT_SOURCE_DIR}/../../" +) + +APPLY_PKG_CONFIG(${TARGET_PKGMGR_UNIT_TEST} PUBLIC + GMOCK_DEPS + GLIB_DEPS + RPC_PORT_DEPS + CAPI_APPFW_EVENT_DEPS + DLOG_DEPS + BUNDLE_DEPS +) + +TARGET_LINK_LIBRARIES(${TARGET_PKGMGR_UNIT_TEST} PUBLIC ${PKGMGR_CLIENT}) +SET_TARGET_PROPERTIES(${TARGET_PKGMGR_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${TARGET_PKGMGR_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie") + +ADD_TEST( + NAME ${TARGET_PKGMGR_UNIT_TEST} + COMMAND ${TARGET_PKGMGR_UNIT_TEST} +) diff --git a/test/unit_tests/main.cc b/test/unit_tests/main.cc new file mode 100644 index 0000000..5f340cd --- /dev/null +++ b/test/unit_tests/main.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include <gtest/gtest.h> +#include <gmock/gmock.h> + +int main(int argc, char** argv) { + int ret = -1; + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() + << std::endl; + } + + return ret; +} diff --git a/test/unit_tests/mock/app_event_mock.cc b/test/unit_tests/mock/app_event_mock.cc new file mode 100644 index 0000000..165caa3 --- /dev/null +++ b/test/unit_tests/mock/app_event_mock.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "mock/app_event_mock.hh" +#include "mock/mock_hook.hh" +#include "mock/test_fixture.hh" + +extern "C" int event_add_event_handler(const char *event_name, + event_cb callback, void *user_data, event_handler_h *event_handler) { + return MOCK_HOOK_P4(AppEventMock, event_add_event_handler, + event_name, callback, user_data, event_handler); +} + +extern "C" int event_remove_event_handler(event_handler_h event_handler) { + return MOCK_HOOK_P1(AppEventMock, event_remove_event_handler, + event_handler); +} + +extern "C" int event_publish_app_event(const char *event_name, + bundle *event_data) { + return MOCK_HOOK_P2(AppEventMock, event_publish_app_event, + event_name, event_data); +} diff --git a/test/unit_tests/mock/app_event_mock.hh b/test/unit_tests/mock/app_event_mock.hh new file mode 100644 index 0000000..fe6af4b --- /dev/null +++ b/test/unit_tests/mock/app_event_mock.hh @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_ +#define UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_ + +#include <app_event.h> +#include <gmock/gmock.h> + +#include "mock/module_mock.hh" + +class AppEventMock : public virtual ModuleMock { + public: + AppEventMock() {} + virtual ~AppEventMock() {} + + MOCK_METHOD(int, event_add_event_handler, (const char*, + event_cb, void*, event_handler_h*)); + MOCK_METHOD(int, event_remove_event_handler, (event_handler_h)); + MOCK_METHOD(int, event_publish_app_event, (const char*, bundle*)); +}; + +#endif // UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_ diff --git a/test/unit_tests/mock/mock_hook.hh b/test/unit_tests/mock/mock_hook.hh new file mode 100644 index 0000000..2980460 --- /dev/null +++ b/test/unit_tests/mock/mock_hook.hh @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNIT_TESTS_MOCK_MOCK_HOOK_HH_ +#define UNIT_TESTS_MOCK_MOCK_HOOK_HH_ + +#define MOCK_HOOK_P0(MOCK_CLASS, f) \ + TestFixture::GetMock<MOCK_CLASS>().f() +#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1) +#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2) +#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3) +#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4) +#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5) +#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6) +#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7) +#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \ + TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8) +#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \ + TestFixture::GetMock<MOCK_CLASS>().f( \ + p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) + +#endif // UNIT_TESTS_MOCK_MOCK_HOOK_HH_ diff --git a/test/unit_tests/mock/module_mock.hh b/test/unit_tests/mock/module_mock.hh new file mode 100644 index 0000000..a79584e --- /dev/null +++ b/test/unit_tests/mock/module_mock.hh @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNIT_TESTS_MOCK_MODULE_MOCK_HH_ +#define UNIT_TESTS_MOCK_MODULE_MOCK_HH_ + +class ModuleMock { + public: + virtual ~ModuleMock() {} +}; + +#endif // UNIT_TESTS_MOCK_MODULE_MOCK_HH_ diff --git a/test/unit_tests/mock/rpc_port_mock.cc b/test/unit_tests/mock/rpc_port_mock.cc new file mode 100644 index 0000000..5295674 --- /dev/null +++ b/test/unit_tests/mock/rpc_port_mock.cc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mock/rpc_port_mock.hh" +#include "mock/mock_hook.hh" +#include "mock/test_fixture.hh" + +RpcPortMock::~RpcPortMock() = default; + +extern "C" int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, + const char *appid, const char *port_name) { + return MOCK_HOOK_P3(RpcPortMock, rpc_port_proxy_connect_sync, + h, appid, port_name); +} + +extern "C" int rpc_port_read(rpc_port_h h, void *buf, unsigned int size) { + return MOCK_HOOK_P3(RpcPortMock, rpc_port_read, + h, buf, size); +} + +extern "C" int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size) { + return MOCK_HOOK_P3(RpcPortMock, rpc_port_write, + h, buf, size); +} + +extern "C" int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, + rpc_port_proxy_connected_event_cb cb, void *user_data) { + return MOCK_HOOK_P3(RpcPortMock, rpc_port_proxy_add_connected_event_cb, + h, cb, user_data); +} + +extern "C" int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, + rpc_port_h port) { + return MOCK_HOOK_P2(RpcPortMock, rpc_port_parcel_create_from_port, + h, port); +} + +extern "C" int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { + return MOCK_HOOK_P2(RpcPortMock, rpc_port_parcel_send, + h, port); +} diff --git a/test/unit_tests/mock/rpc_port_mock.hh b/test/unit_tests/mock/rpc_port_mock.hh new file mode 100644 index 0000000..2536d5a --- /dev/null +++ b/test/unit_tests/mock/rpc_port_mock.hh @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_ +#define UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_ + +#include <rpc-port.h> +#include <rpc-port-parcel.h> +#include <gmock/gmock.h> + +#include "mock/module_mock.hh" + +class RpcPortMock : public virtual ModuleMock { + public: + RpcPortMock() { + using ::testing::_; + using ::testing::Invoke; + + ON_CALL(*this, rpc_port_proxy_add_connected_event_cb(_, _, _)) + .WillByDefault(Invoke([&](rpc_port_proxy_h h, + rpc_port_proxy_connected_event_cb cb, void* data) { + connected_event_cb_ = cb; + connected_event_data_ = data; + return 0; + })); + ON_CALL(*this, rpc_port_proxy_connect_sync(_, _, _)) + .WillByDefault(Invoke([&](rpc_port_proxy_h, const char*, const char*) { + if (connected_event_cb_) { + static int dummy; + rpc_port_h port = (rpc_port_h)&dummy; + connected_event_cb_("pkgmgr-server", "mockport", port, + connected_event_data_); + } + return 0; + })); + } + + virtual ~RpcPortMock(); + + MOCK_METHOD(int, rpc_port_proxy_connect_sync, (rpc_port_proxy_h, + const char*, const char*)); + MOCK_METHOD(int, rpc_port_read, (rpc_port_h, void*, unsigned int)); + MOCK_METHOD(int, rpc_port_write, (rpc_port_h, const void*, unsigned int)); + MOCK_METHOD(int, rpc_port_proxy_add_connected_event_cb, + (rpc_port_proxy_h, rpc_port_proxy_connected_event_cb, void*)); + MOCK_METHOD(int, rpc_port_parcel_create_from_port, + (rpc_port_parcel_h*, rpc_port_h)); + MOCK_METHOD(int, rpc_port_parcel_send, (rpc_port_parcel_h, rpc_port_h)); + + private: + rpc_port_proxy_connected_event_cb connected_event_cb_ = nullptr; + void* connected_event_data_ = nullptr; +}; + +#endif // UNIT_TESTS_MOCK_RPC_PORT_MOCK_HH_ diff --git a/test/unit_tests/mock/test_fixture.cc b/test/unit_tests/mock/test_fixture.cc new file mode 100644 index 0000000..23f907d --- /dev/null +++ b/test/unit_tests/mock/test_fixture.cc @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include "unit_tests/mock/test_fixture.hh" + +std::unique_ptr<ModuleMock> TestFixture::mock_; diff --git a/test/unit_tests/mock/test_fixture.hh b/test/unit_tests/mock/test_fixture.hh new file mode 100644 index 0000000..8351374 --- /dev/null +++ b/test/unit_tests/mock/test_fixture.hh @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UNIT_TESTS_MOCK_TEST_FIXTURE_HH_ +#define UNIT_TESTS_MOCK_TEST_FIXTURE_HH_ + +#include <gtest/gtest.h> + +#include <memory> +#include <stdexcept> +#include <string> +#include <utility> + +#include "unit_tests/mock/module_mock.hh" + +class TestFixture : public ::testing::Test { + public: + explicit TestFixture(std::unique_ptr<ModuleMock> mock) { + mock_ = std::move(mock); + } + + virtual ~TestFixture() {} + + virtual void SetUp() {} + virtual void TearDown() {} + + template <typename T> + static T& GetMock() { + auto ptr = dynamic_cast<T*>(mock_.get()); + if (ptr == nullptr) { + throw std::invalid_argument("The test does not provide mock of \"" + + std::string(typeid(T).name()) + "\""); + } + + return *ptr; + } + + static std::unique_ptr<ModuleMock> mock_; +}; + +#endif // UNIT_TESTS_MOCK_TEST_FIXTURE_HH_ diff --git a/test/unit_tests/test_client.cc b/test/unit_tests/test_client.cc new file mode 100644 index 0000000..36a0edb --- /dev/null +++ b/test/unit_tests/test_client.cc @@ -0,0 +1,975 @@ +#include "package-manager.h" + +#include <gtest/gtest.h> +#include <gmock/gmock.h> + +#include "unit_tests/mock/rpc_port_mock.hh" +#include "unit_tests/mock/app_event_mock.hh" +#include "unit_tests/mock/test_fixture.hh" + +using ::testing::_; +using ::testing::Invoke; + +namespace { +class Mocks : public ::testing::NiceMock<RpcPortMock>, + virtual public ::testing::NiceMock<AppEventMock> {}; + +} // namespace + +class ClientTest : public TestFixture { + public: + ClientTest() : TestFixture(std::make_unique<::Mocks>()) {} + + virtual void SetUp() { + handle_ = pkgmgr_client_new(PC_REQUEST); + handler_ = [](uid_t target_uid, int req_id, + const char* pkg_type, const char* pkgid, const char* key, + const char* val, const void* pmsg, void* data) { + return 0; + }; + app_handler_ = [](uid_t target_uid, int req_id, const char *pkg_type, + const char *pkgid, const char *appid, const char *key, + const char *val, const void *pmsg, void *data) { + return 0; + }; + pkg_size_handler_ = [](pkgmgr_client *pc, const char *pkgid, + const pkg_size_info_t *size_info, void *user_data) { + }; + + ON_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .WillByDefault(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_string(parcel, "req_key"); + rpc_port_parcel_write_int32(parcel, 0); + *h = parcel; + return 0; + })); + } + + virtual void TearDown() { + if (handle_) + pkgmgr_client_free(handle_); + } + + pkgmgr_client* GetHandle() { + return handle_; + } + + pkgmgr_handler GetDefaultHandler() { + return handler_; + } + + pkgmgr_app_handler GetDefaultAppHandler() { + return app_handler_; + } + + pkgmgr_pkg_size_info_receive_cb GetDefaultPkgSizeHandler() { + return pkg_size_handler_; + } + + private: + pkgmgr_client* handle_ = nullptr; + pkgmgr_handler handler_ = nullptr; + pkgmgr_app_handler app_handler_ = nullptr; + pkgmgr_pkg_size_info_receive_cb pkg_size_handler_ = nullptr; +}; + +TEST_F(ClientTest, pkgmgr_client_set_tep_path) { + int ret = pkgmgr_client_set_tep_path(GetHandle(), "/tmp/test.tep", true); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_set_tep_path_n) { + int ret = pkgmgr_client_set_tep_path(GetHandle(), nullptr, true); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_install_packages) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* paths[3] = { "/tmp/a.tpk", "/tmp/b.tpk", "/tmp/c.tpk" }; + int ret = pkgmgr_client_install_packages(GetHandle(), paths, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_install_packages_n) { + int ret = pkgmgr_client_install_packages(GetHandle(), nullptr, 0, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_install) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_install(GetHandle(), "tpk", "/tmp/desc" + , "/tmp/test.tpk", "", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_install_n) { + int ret = pkgmgr_client_install(GetHandle(), "tpk", "/tmp/desc" + , nullptr, "", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_reinstall) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_reinstall(GetHandle(), "tpk", "org.tizen.test" + ,"", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + + +TEST_F(ClientTest, pkgmgr_client_reinstall_n) { + int ret = pkgmgr_client_reinstall(GetHandle(), "tpk", nullptr, + "", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_uninstall_packages) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* pkgs[3] = { "/tmp/a.tpk", "/tmp/b.tpk", "/tmp/c.tpk" }; + int ret = pkgmgr_client_uninstall_packages(GetHandle(), pkgs, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_uninstall_packages_n) { + int ret = pkgmgr_client_uninstall_packages(GetHandle(), nullptr, 0, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_uninstall) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_uninstall(GetHandle(), "tpk", "org.tizen.test", + PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_uninstall_n) { + int ret = pkgmgr_client_uninstall(GetHandle(), "tpk", nullptr, + PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_move) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_move(GetHandle(), "tpk", "org.tizen.test", + PM_MOVE_TO_SDCARD, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_move_n) { + int ret = pkgmgr_client_move(GetHandle(), "tpk", nullptr, + PM_MOVE_TO_SDCARD, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_mount_install) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_mount_install(GetHandle(), "tpk", "/tmp", + "/tmp/test.tpk", "", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_mount_install_n) { + int ret = pkgmgr_client_mount_install(GetHandle(), "tpk", "/tmp", + nullptr, "", PM_DEFAULT, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_mount_install_packages) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* paths[3] = { "/tmp/a.tpk", "/tmp/b.tpk", "/tmp/c.tpk" }; + int ret = pkgmgr_client_mount_install_packages(GetHandle(), paths, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_mount_install_packages_n) { + int ret = pkgmgr_client_mount_install_packages(GetHandle(), nullptr, 0, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_register_pkg_update_info) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + pkg_update_info_t info = { + .pkgid = const_cast<char*>("org.tizen.test"), + .version = const_cast<char*>("1.0.0"), + .type = PM_UPDATEINFO_TYPE_FORCE + }; + int ret = pkgmgr_client_register_pkg_update_info(GetHandle(), &info); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_register_pkg_update_info_n) { + int ret = pkgmgr_client_register_pkg_update_info(GetHandle(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_unregister_pkg_update_info) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_unregister_pkg_update_info(GetHandle(), + "org.tizen.test"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_unregister_pkg_update_info_n) { + int ret = pkgmgr_client_unregister_pkg_update_info(GetHandle(), + nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_unregister_all_pkg_update_info) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_unregister_all_pkg_update_info(GetHandle()); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_unregister_all_pkg_update_info_n) { + int ret = pkgmgr_client_unregister_all_pkg_update_info(nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_activate) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_activate(GetHandle(), "tpk", "org.tizen.test"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_activate_n) { + int ret = pkgmgr_client_activate(GetHandle(), "tpk", nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_activate_packages) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* pkgs[3] = { "org.tizen.test1", "org.tizen.test2", + "org.tizen.test3" }; + int ret = pkgmgr_client_activate_packages(GetHandle(), "tpk", pkgs, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_activate_packages_n) { + int ret = pkgmgr_client_activate_packages(GetHandle(), "tpk", nullptr, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_deactivate(GetHandle(), "tpk", "org.tizen.test1"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_n) { + int ret = pkgmgr_client_deactivate(GetHandle(), "tpk", nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_packages) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* pkgs[3] = { "org.tizen.test1", "org.tizen.test2", + "org.tizen.test3" }; + int ret = pkgmgr_client_deactivate_packages(GetHandle(), "tpk", pkgs, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_packages_n) { + int ret = pkgmgr_client_deactivate_packages(GetHandle(), "tpk", nullptr, 3, + GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_activate_app) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_activate_app(GetHandle(), "org.tizen.test", + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_activate_app_n) { + int ret = pkgmgr_client_activate_app(GetHandle(), nullptr, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_activate_apps) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* apps[3] = { "org.tizen.test1", "org.tizen.test2", + "org.tizen.test3" }; + int ret = pkgmgr_client_activate_apps(GetHandle(), apps, 3, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_activate_apps_n) { + int ret = pkgmgr_client_activate_apps(GetHandle(), nullptr, 3, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_activate_global_app_for_uid) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_activate_global_app_for_uid(GetHandle(), + "org.tizen.test1", GetDefaultAppHandler(), nullptr, 0); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_activate_global_app_for_uid_n) { + int ret = pkgmgr_client_activate_global_app_for_uid(GetHandle(), nullptr, + GetDefaultAppHandler(), nullptr, 0); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_app) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_deactivate_app(GetHandle(), "org.tizen.test", + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_app_n) { + int ret = pkgmgr_client_deactivate_app(GetHandle(), nullptr, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_apps) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + const char* apps[3] = { "org.tizen.test1", "org.tizen.test2", + "org.tizen.test3" }; + int ret = pkgmgr_client_deactivate_apps(GetHandle(), apps, 3, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_apps_n) { + int ret = pkgmgr_client_deactivate_apps(GetHandle(), nullptr, 3, + GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_global_app_for_uid) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_deactivate_global_app_for_uid(GetHandle(), + "org.tizen.test1", GetDefaultAppHandler(), nullptr, 0); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_deactivate_global_app_for_uid_n) { + int ret = pkgmgr_client_deactivate_global_app_for_uid(GetHandle(), nullptr, + GetDefaultAppHandler(), nullptr, 0); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_clear_user_data) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_clear_user_data(GetHandle(), "tpk", + "org.tizen.test1", PM_DEFAULT); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_clear_user_data_n) { + int ret = pkgmgr_client_clear_user_data(GetHandle(), "tpk", + nullptr, PM_DEFAULT); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_listen_status) { + int ret = pkgmgr_client_listen_status(GetHandle(), GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_listen_status_n) { + int ret = pkgmgr_client_listen_status(nullptr, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_listen_app_status) { + int ret = pkgmgr_client_listen_app_status(GetHandle(), GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_listen_app_status_n) { + int ret = pkgmgr_client_listen_app_status(nullptr, GetDefaultAppHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_get_size) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_get_size(GetHandle(), "org.tizen.test", + PM_GET_PKG_SIZE_INFO, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_get_size_n) { + int ret = pkgmgr_client_get_size(GetHandle(), nullptr, + PM_GET_PKG_SIZE_INFO, GetDefaultHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_get_package_size_info) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1); + + int ret = pkgmgr_client_get_package_size_info(GetHandle(), "org.tizen.test", + GetDefaultPkgSizeHandler(), nullptr); + EXPECT_TRUE(ret > 0); +} + +TEST_F(ClientTest, pkgmgr_client_get_package_size_info_n) { + int ret = pkgmgr_client_get_package_size_info(GetHandle(), nullptr, + GetDefaultPkgSizeHandler(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_generate_license_request) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, 0); + rpc_port_parcel_write_int32(parcel, 0); + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + char* req_data = nullptr; + char* license_url = nullptr; + int ret = pkgmgr_client_generate_license_request(GetHandle(), "data", + &req_data, &license_url); + EXPECT_TRUE(ret == PKGMGR_R_OK); + free(req_data); + free(license_url); +} + +TEST_F(ClientTest, pkgmgr_client_generate_license_request_n) { + int ret = pkgmgr_client_generate_license_request(GetHandle(), nullptr, + nullptr, nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_register_license) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_register_license(GetHandle(), "data"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_register_license_n) { + int ret = pkgmgr_client_register_license(GetHandle(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_decrypt_package) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_decrypt_package(GetHandle(), "path1", "path2"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_decrypt_package_n) { + int ret = pkgmgr_client_decrypt_package(GetHandle(), nullptr, nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_enable_splash_screen) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_enable_splash_screen(GetHandle(), "org.tizen.test1"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_enable_splash_screen_n) { + int ret = pkgmgr_client_enable_splash_screen(GetHandle(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_disable_splash_screen) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_disable_splash_screen(GetHandle(), "org.tizen.test1"); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_disable_splash_screen_n) { + int ret = pkgmgr_client_disable_splash_screen(GetHandle(), nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_set_pkg_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_set_pkg_restriction_mode(GetHandle(), "org.tizen.test1", 1); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_set_pkg_restriction_mode_n) { + int ret = pkgmgr_client_set_pkg_restriction_mode(GetHandle(), nullptr, 0); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_unset_pkg_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_unset_pkg_restriction_mode(GetHandle(), "org.tizen.test1", 1); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_unset_pkg_restriction_mode_n) { + int ret = pkgmgr_client_unset_pkg_restriction_mode(GetHandle(), nullptr, 0); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_get_pkg_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, 1); // mode + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int mode = 0; + int ret = pkgmgr_client_get_pkg_restriction_mode(GetHandle(), + "org.tizen.test1", &mode); + EXPECT_TRUE(ret == PKGMGR_R_OK); + EXPECT_TRUE(mode == 1); +} + +TEST_F(ClientTest, pkgmgr_client_get_pkg_restriction_mode_n) { + int mode; + int ret = pkgmgr_client_get_pkg_restriction_mode(GetHandle(), nullptr, &mode); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_set_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_set_restriction_mode(GetHandle(), 2); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_set_restriction_mode_n) { + int ret = pkgmgr_client_set_restriction_mode(nullptr, 2); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_unset_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_unset_restriction_mode(GetHandle(), 2); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_unset_restriction_mode_n) { + int ret = pkgmgr_client_unset_restriction_mode(nullptr, 2); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_get_restriction_mode) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, 2); // mode + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int mode = 0; + int ret = pkgmgr_client_get_restriction_mode(GetHandle(), &mode); + EXPECT_TRUE(ret == PKGMGR_R_OK); + EXPECT_TRUE(mode == 2); +} + +TEST_F(ClientTest, pkgmgr_client_get_restriction_mode_n) { + int mode = 0; + int ret = pkgmgr_client_get_restriction_mode(nullptr, &mode); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_set_app_label) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_set_app_label(GetHandle(), + const_cast<char*>("org.tizen.test1"), const_cast<char*>("test1")); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_set_app_label_n) { + int ret = pkgmgr_client_set_app_label(nullptr, nullptr, nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_set_app_icon) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_set_app_icon(GetHandle(), + const_cast<char*>("org.tizen.test1"), const_cast<char*>("path")); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_set_app_icon_n) { + int ret = pkgmgr_client_set_app_icon(nullptr, nullptr, nullptr); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} + +TEST_F(ClientTest, pkgmgr_client_usr_migrate_external_image) { + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_proxy_connect_sync(_, _, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_send(_, _)) + .Times(1); + EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_parcel_create_from_port(_, _)) + .Times(1) + .WillOnce(Invoke([&](rpc_port_parcel_h* h, rpc_port_h port) { + rpc_port_parcel_h parcel; + rpc_port_parcel_create(&parcel); + rpc_port_parcel_write_int32(parcel, 0); // __Result + rpc_port_parcel_write_int32(parcel, PKGMGR_R_OK); + *h = parcel; + return 0; + })); + + int ret = pkgmgr_client_usr_migrate_external_image(GetHandle(), + "org.tizen.test1", 0); + EXPECT_TRUE(ret == PKGMGR_R_OK); +} + +TEST_F(ClientTest, pkgmgr_client_usr_migrate_external_image_n) { + int ret = pkgmgr_client_usr_migrate_external_image(nullptr, + "org.tizen.test1", 0); + EXPECT_TRUE(ret == PKGMGR_R_EINVAL); +} diff --git a/tidl/PkgMgr.tidl b/tidl/PkgMgr.tidl new file mode 100755 index 0000000..f87e0bf --- /dev/null +++ b/tidl/PkgMgr.tidl @@ -0,0 +1,71 @@ +// tidlc -s -l C++ -i PkgMgr.tidl -o PkgMgrStub
+// tidlc -p -l C++ -i PkgMgr.tidl -o PkgMgrProxy
+
+struct ResPath
+{
+ string From;
+ string To;
+}
+
+[privilege="http://tizen.org/privilege/packagemanager.clearcache"]
+interface PkgMgrForClearCache
+{
+ int ClearCache(int uid, string pkgid);
+}
+
+[privilege="http://tizen.org/privilege/packagemanager.info"]
+interface PkgMgr
+{
+ int GetSize(int uid, string pkgid, int getType, out string reqKey);
+ int GetSizeSync(int uid, string pkgid, int getType, out long sizeInfo);
+ int Check(int uid, string pkgid, out int pid);
+}
+
+[privilege = "http://tizen.org/privilege/packagemanager.admin"]
+interface PkgMgrAdmin
+{
+ int Install(int uid, string pkgType, string pkgPath, array<string> args, string reqId, out string reqKey);
+ int InstallPkgs(int uid, array<string> pkgs, array<string> args, string reqId, out string reqKey);
+ int Reinstall(int uid, string pkgid, out string reqKey);
+ int MountInstall(int uid, string pkgType, string pkgPath, array<string> args, string reqId, out string reqKey);
+ int MountInstallPkgs(int uid, array<string> pkgs, string reqId, out string reqKey);
+ int Uninstall(int uid, string pkgid, out string reqKey);
+ int UninstallPkgs(int uid, array<string> pkgs, out string reqKey);
+ int Move(int uid, string pkgId, int moveType, out string reqKey);
+ int EnablePkgs(int uid, array<string> pkgIds, out string reqKey);
+ int DisablePkgs(int uid, array<string> pkgIds, out string reqKey);
+ int RegisterPkgUpdateInfo(int uid, string pkgid, string version, int type);
+ int UnregisterPkgUpdateInfo(int uid, string pkgid);
+ int UnregisterAllPkgUpdateInfo(int uid);
+ int EnableApp(int uid, string appid, out string reqKey);
+ int DisableApp(int uid, string appid, out string reqKey);
+ int EnableApps(int uid, array<string> appIds, out string reqKey);
+ int DisableApps(int uid, array<string> appIds, out string reqKey);
+ int EnableGlobalAppForUid(int uid, string appid, out string reqKey);
+ int DisableGlobalAppForUid(int uid, string appid, out string reqKey);
+ int Kill(int uid, string pkgid, out int pid);
+ int GenerateLicenseRequest(string respData, out string reqData, out string licenseUrl);
+ int RegisterLicense(string respData);
+ int DecryptPackage(string drmFilePath, string decryptedFilePath);
+ int EnableAppSplashScreen(int uid, string appid);
+ int DisableAppSplashScreen(int uid, string appid);
+ int SetRestrictionMode(int uid, string pkgid, int mode);
+ int UnsetRestrictionMode(int uid, string pkgid, int mode);
+ int GetRestrictionMode(int uid, string pkgid, out int result);
+ int SetAppLabel(int uid, string appid, string label);
+ int SetAppIcon(int uid, string appid, string iconPath);
+ int MigrateExternalImage(int uid, string pkgid);
+ int ResCopy(array<ResPath> copyPathsPair, out string reqKey);
+ int ResCreateDir(array<string> createDirPaths, out string reqKey);
+ int ResRemove(array<string> removePaths, out string reqKey);
+ int ResUninstall(int uid, string pkgid);
+ int ClearData(int uid, string pkgid);
+}
+
+
+
+
+
+
+
+
diff --git a/tidl/PkgSignal.tidl b/tidl/PkgSignal.tidl new file mode 100644 index 0000000..0470b16 --- /dev/null +++ b/tidl/PkgSignal.tidl @@ -0,0 +1,28 @@ +// tidlc -g -l C++ -i PkgSignal.tidl -o PkgSignal
+
+struct PkgInfo
+{
+ string Pkgid;
+ string Appid;
+ string PkgType;
+}
+
+struct PathInfo
+{
+ string Path;
+ int State;
+}
+
+struct ExtraData
+{
+ int ErrCode;
+ array<PathInfo> Paths;
+}
+
+interface PkgSignal
+{
+ void AsyncResult(int targetUid, string reqId, array<PkgInfo> pkgs, string key, string val) async;
+ void AsyncResultForResource(int targetUid, string reqId, string pkgid, string status, ExtraData extra) async;
+}
+
+
diff --git a/tidl/prebuild.sh b/tidl/prebuild.sh new file mode 100755 index 0000000..2670821 --- /dev/null +++ b/tidl/prebuild.sh @@ -0,0 +1,5 @@ +#!/bin/bash +tidlc -p -l C++ -i PkgMgr.tidl -o PkgMgrProxy +tidlc -g -l C++ -i PkgSignal.tidl -o PkgSignal + + |