diff options
author | Juhee park <juhee82.park@samsung.com> | 2018-04-25 10:31:11 +0900 |
---|---|---|
committer | Juhee Park <juhee82.park@samsung.com> | 2018-05-03 10:51:59 +0900 |
commit | 1af37e69fd7946a1049fb8b5448353bec9c891d4 (patch) | |
tree | 59866282b2307357e7180b655990932704ff0412 | |
parent | c55210b5e36a5f2a96ea3b09b63d1bf1c413b277 (diff) | |
download | ttsd-worker-package-1af37e69fd7946a1049fb8b5448353bec9c891d4.tar.gz ttsd-worker-package-1af37e69fd7946a1049fb8b5448353bec9c891d4.tar.bz2 ttsd-worker-package-1af37e69fd7946a1049fb8b5448353bec9c891d4.zip |
add uninstall operation, modified appcontrol cb
Change-Id: Ib122efea1463163144fc69c650096ca705465f53
-rw-r--r-- | CMakeLists.txt | 89 | ||||
-rw-r--r-- | inc/pm_downloader.h | 1 | ||||
-rw-r--r-- | inc/pm_result.h | 2 | ||||
-rw-r--r-- | inc/pm_uninstaller.h | 24 | ||||
-rw-r--r-- | src/pm_downloader.c | 6 | ||||
-rw-r--r-- | src/pm_installer.c | 1 | ||||
-rw-r--r-- | src/pm_result.c | 14 | ||||
-rw-r--r-- | src/pm_uninstaller.c | 85 | ||||
-rw-r--r-- | src/pm_worker.c | 124 |
9 files changed, 261 insertions, 85 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 76d2424..cdfb349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,45 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(package-manager-worker C)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(APP_PKGS REQUIRED
- dlog
- capi-appfw-service-application
- capi-appfw-package-manager
- capi-appfw-app-manager
- glib-2.0
- json-glib-1.0
- libcurl
-)
-
-FOREACH (flag ${APP_PKGS_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline -g -fno-builtin-malloc -fPIE")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc)
-
-SET(SRCS
- src/pm_worker.c
- src/pm_downloader.c
- src/pm_installer.c
- src/pm_result.c
- src/pm_report.c
-)
-ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm ${APP_PKGS_LDFLAGS})
-
-SET(VENDOR "tizen")
-SET(PACKAGE ${PROJECT_NAME})
-SET(PKGNAME "org.${VENDOR}.${PACKAGE}")
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(BINDIR "${PREFIX}/bin")
-
-# application xml
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
-INSTALL(FILES ${CMAKE_BINARY_DIR}/${PKGNAME}.xml DESTINATION ${SYS_PACKAGES_DIR})
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(package-manager-worker C) + +INCLUDE(FindPkgConfig) +pkg_check_modules(APP_PKGS REQUIRED + dlog + capi-appfw-service-application + capi-appfw-package-manager + capi-appfw-app-manager + glib-2.0 + json-glib-1.0 + libcurl +) + +FOREACH (flag ${APP_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline -g -fno-builtin-malloc -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) + +SET(SRCS + src/pm_worker.c + src/pm_downloader.c + src/pm_installer.c + src/pm_result.c + src/pm_report.c + src/pm_uninstaller.c +) +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm ${APP_PKGS_LDFLAGS}) + +SET(VENDOR "tizen") +SET(PACKAGE ${PROJECT_NAME}) +SET(PKGNAME "org.${VENDOR}.${PACKAGE}") +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(BINDIR "${PREFIX}/bin") + +# application xml +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) +INSTALL(FILES ${CMAKE_BINARY_DIR}/${PKGNAME}.xml DESTINATION ${SYS_PACKAGES_DIR}) diff --git a/inc/pm_downloader.h b/inc/pm_downloader.h index 99196e4..73c4ec5 100644 --- a/inc/pm_downloader.h +++ b/inc/pm_downloader.h @@ -26,6 +26,7 @@ typedef struct { } pm_downloader_metadata_s; pm_downloader_metadata_s *pm_downloader_get_metadata(const char *url); +pm_downloader_metadata_s *pm_downloader_parsing_metadata(const char *data); bool pm_downloader_check_compatibility(const char *hash, const char* file_path); char *pm_downloader_download(const char *url, const char *file_name, const char *download_dir); diff --git a/inc/pm_result.h b/inc/pm_result.h index 23bb309..9401fb3 100644 --- a/inc/pm_result.h +++ b/inc/pm_result.h @@ -20,6 +20,8 @@ #include <stdbool.h> char *pm_result_get_install(const char* package, bool success, const char *reason); +char *pm_result_get_uninstall(const char* pkg_name, bool success, const char *reason); + bool pm_result_get_package_information(void); bool pm_result_get_application_information(void); diff --git a/inc/pm_uninstaller.h b/inc/pm_uninstaller.h new file mode 100644 index 0000000..47dd4fe --- /dev/null +++ b/inc/pm_uninstaller.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 __PM_UNINSTALLER_H__ +#define __PM_UNINSTALLER_H__ + +typedef void (*pm_uninstaller_res_cb)(const char *package, int result, void *user_data); + +int pm_uninstaller_uninstall(const char *name, pm_uninstaller_res_cb result_cb, void *cb_data); + +#endif /* __PM_UNINSTALLER_H__ */ diff --git a/src/pm_downloader.c b/src/pm_downloader.c index 2cbea73..7eabd8d 100644 --- a/src/pm_downloader.c +++ b/src/pm_downloader.c @@ -55,7 +55,7 @@ static size_t _write_file(void *ptr, size_t size, size_t nmemb, FILE *stream) return written; } -pm_downloader_metadata_s *_parsing_metadata(const char *data) +pm_downloader_metadata_s *pm_downloader_parsing_metadata(const char *data) { pm_downloader_metadata_s *ret = NULL; JsonParser *parser = json_parser_new(); @@ -123,7 +123,7 @@ pm_downloader_metadata_s *pm_downloader_get_metadata(const char *url) _E("curl_easy_perform() failed: %s", curl_easy_strerror(res)); else { _D("Download Success: {%s}", data); - ret = _parsing_metadata(data); + ret = pm_downloader_parsing_metadata(data); } } @@ -137,6 +137,7 @@ pm_downloader_metadata_s *pm_downloader_get_metadata(const char *url) bool pm_downloader_check_compatibility(const char *hash, const char* file_path) { + FILE *fp = fopen (file_path, "rb"); int bytes = 0; GChecksum *checksum = NULL; @@ -168,6 +169,7 @@ bool pm_downloader_check_compatibility(const char *hash, const char* file_path) } g_checksum_free(checksum); return true; + } char *pm_downloader_download(const char *url, const char *file_name, const char *download_dir) diff --git a/src/pm_installer.c b/src/pm_installer.c index 7555dad..ce3251c 100644 --- a/src/pm_installer.c +++ b/src/pm_installer.c @@ -83,3 +83,4 @@ int pm_installer_install(const char *path, pm_installer_res_cb result_cb, void * return 0; } + diff --git a/src/pm_result.c b/src/pm_result.c index 5fbb693..bb44ab3 100644 --- a/src/pm_result.c +++ b/src/pm_result.c @@ -22,13 +22,14 @@ #include "log.h" #define FILE_PATH "/tmp/result.json" - -char *pm_result_get_install(const char* package, bool success, const char *reason) +char *_pm_result_get_operation(const char* type, const char* package, bool success, const char *reason) { JsonBuilder *builder = json_builder_new(); char *res_str = NULL; json_builder_begin_object (builder); + json_builder_set_member_name (builder, "operation"); + json_builder_add_string_value (builder, type); json_builder_set_member_name (builder, "package"); json_builder_add_string_value (builder, package); json_builder_set_member_name (builder, "status"); @@ -52,6 +53,15 @@ char *pm_result_get_install(const char* package, bool success, const char *reaso builder = NULL; return res_str; + +} +char *pm_result_get_install(const char* package, bool success, const char *reason) +{ + return _pm_result_get_operation("install", package, success, reason); +} +char *pm_result_get_uninstall(const char* pkg_name, bool success, const char *reason) +{ + return _pm_result_get_operation("uninstall", pkg_name, success, reason); } static bool diff --git a/src/pm_uninstaller.c b/src/pm_uninstaller.c new file mode 100644 index 0000000..0a108ed --- /dev/null +++ b/src/pm_uninstaller.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "log.h" +#include "pm_uninstaller.h" +#include <package_manager.h> +#include <glib.h> + + +typedef struct __pm_uninstaller_s { + package_manager_request_h handle; + int request_id; + pm_uninstaller_res_cb result_cb; + void * cb_data; +} pm_uninstaller_s; + +static void _uninstall_cb(int id, const char *type, const char *package, + package_manager_event_type_e event_type, + package_manager_event_state_e event_state, int progress, + package_manager_error_e error, void *user_data) +{ + pm_uninstaller_s *pmu_d = user_data; + + if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) { + if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { + _D("Unnstall Success"); + if (pmu_d->result_cb) + pmu_d->result_cb(package, 0, pmu_d->cb_data); + package_manager_request_destroy(pmu_d->handle); + g_free(pmu_d); + + } else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) { + _E("Uninstall Fail (%d)", error); + if (pmu_d->result_cb) + pmu_d->result_cb(package, -1, pmu_d->cb_data); /* TODO : set error code from result value */ + package_manager_request_destroy(pmu_d->handle); + g_free(pmu_d); + } + } +} + +int pm_uninstaller_uninstall(const char *name, pm_uninstaller_res_cb result_cb, void *cb_data) +{ + _D("Uninstall Start"); + int ret = 0; + int request_id = 0; + pm_uninstaller_s *pmu_d = NULL; + + pmu_d = g_malloc0(sizeof(pm_uninstaller_s)); + pmu_d->result_cb = result_cb; + pmu_d->cb_data = cb_data; + + ret = package_manager_request_create(&pmu_d->handle); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + _E("Fail create package manager request handle : %d(%s)", ret, + get_error_message(ret)); + g_free(pmu_d); + return -1; + } + + ret = package_manager_request_uninstall_with_cb(pmu_d->handle, name, _uninstall_cb, + pmu_d, &request_id); + + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + _E("Fail request package manager install : %d(%s)", ret, + get_error_message(ret)); + g_free(pmu_d); + return -1; + } + + return 0; +}
\ No newline at end of file diff --git a/src/pm_worker.c b/src/pm_worker.c index 1e4a8a0..5f0aae5 100644 --- a/src/pm_worker.c +++ b/src/pm_worker.c @@ -17,12 +17,13 @@ #include "log.h" #include "pm_downloader.h" #include "pm_installer.h" +#include "pm_uninstaller.h" #include "pm_report.h" #include "pm_result.h" #include <service_app.h> #include <stdlib.h> -#define TEST_URL "https://test.showiot.xyz/api/package/metadata?id=test-page1523421701067&key=175b6545cca4f96bcd9ff2d1dcd6666bbafb1bec" +#define TEST_STR "{\"id\": \"test-page1524536333414p\",\"filename\": \"org.tizen.example.CustomRenderer.Tizen.Mobile-1.0.0.tpk\",\"url\": \"https://d3d0p8vzmg5wus.cloudfront.net/test-page1524536333414p/org.tizen.example.CustomRenderer.Tizen.Mobile-1.0.0.tpk?Expires=1525141135&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kM2QwcDh2em1nNXd1cy5jbG91ZGZyb250Lm5ldC90ZXN0LXBhZ2UxNTI0NTM2MzMzNDE0cC9vcmcudGl6ZW4uZXhhbXBsZS5DdXN0b21SZW5kZXJlci5UaXplbi5Nb2JpbGUtMS4wLjAudHBrIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNTI1MTQxMTM1fX19XX0_&Signature=cmx0DdSSU~fA3qyq0amdNa8mD2lSxHTnwoolAn1GimetKer7qThcvfCjlGB6bCe2b4sEinxaSVPmsKfewLFrlsa8W1yZeFLzJlIi1bBywgAeYUfut3~OgnMUqlWsByzitxcjJk4f6Wpdm5gJmkPMDXS4YnmyolAZZFEM5npVCtxbSObaaPJ~IgmiuCbHzioIbs~DBKw1-zfECkB~yKRi7exCat-zELDtj8i28M~~qlDNDOLm5PI3~Qkbem4najid4xKlgGnn3hnlSxqeJYbCGNzbt4dwwJ9kRIT7MB8ul~V3t0IY9cfxqEVA61MwTjHrJnYbMP3J43fYQpDY~XWGhw__&Key-Pair-Id=APKAIKWABALTNMYO2CWA\",\"hash\": \"64d16fa812b967e40ae02f27489aefae\"}" static void __pkg_install_result_callback(const char *package, int result, void *user_data) @@ -36,6 +37,23 @@ __pkg_install_result_callback(const char *package, int result, void *user_data) pm_worker_report_result(result_str); free(result_str); + + service_app_exit(); +} + +static void +__pkg_uninstall_result_callback(const char *package, int result, void *user_data) +{ + char *result_str = NULL; + + if (result) + result_str = pm_result_get_uninstall(package, false, "UNINSTALL_PKG_FAILED"); + else + result_str = pm_result_get_uninstall(package, true, "UNINSTALL_PKG_SUCCESS"); + + pm_worker_report_result(result_str); + free(result_str); + service_app_exit(); } @@ -49,6 +67,7 @@ static bool service_app_create(void *data) static void service_app_terminate(void *data) { // Todo: add your code here. + _D("On terminate"); return; } @@ -56,58 +75,89 @@ static void service_app_control(app_control_h app_control, void *data) { // TODO : Get pkg url from app control data - char *downloaded_pkg = NULL; + char *downloaded_pkg_path = NULL; char *data_path = NULL; char *result_str = NULL; bool error = false; bool is_valid = false; + bool exit = false; + int ret = 0; pm_downloader_metadata_s * metadata = NULL; data_path = app_get_data_path(); - metadata = pm_downloader_get_metadata(TEST_URL); - if (!metadata) { - result_str = pm_result_get_install(TEST_URL, false, "GET_META_FAILED"); - pm_worker_report_result(result_str); - service_app_exit(); - return; - } - - downloaded_pkg = pm_downloader_download(metadata->url, metadata->file_name, data_path); + char *operation = NULL; + app_control_get_extra_data(app_control, "operation", &operation); + if(!strcmp(operation, "install")) + { + metadata = pm_downloader_parsing_metadata(TEST_STR); + if (!metadata) { + result_str = pm_result_get_install(TEST_STR, false, "GET_META_FAILED"); + pm_worker_report_result(result_str); + service_app_exit(); + return; + } - free(data_path); + downloaded_pkg_path = pm_downloader_download(metadata->url, metadata->file_name, data_path); - if (!downloaded_pkg) { - /* TODO : Reasons should be redefined */ - result_str = pm_result_get_install(downloaded_pkg, false, "DOWNLOAD_FAILED"); - pm_worker_report_result(result_str); - error = true; - } else { - is_valid = pm_downloader_check_compatibility(metadata->hash, downloaded_pkg); + free(data_path); - if(!is_valid) { - result_str = pm_result_get_install(downloaded_pkg, false, "HASH_CHECK_FAILED"); + if (!downloaded_pkg_path) { + /* TODO : Reasons should be redefined */ + result_str = pm_result_get_install(downloaded_pkg_path, false, "DOWNLOAD_FAILED"); + pm_worker_report_result(result_str); error = true; - } - else { - int ret = 0; - ret = pm_installer_install( - downloaded_pkg, __pkg_install_result_callback, NULL); - - if (ret) { - /* TODO : Reasons should be redefined */ - result_str = pm_result_get_install(downloaded_pkg, false, "PKG_MANAGER_ERROR"); - pm_worker_report_result(result_str); + } else { + is_valid = pm_downloader_check_compatibility(metadata->hash, downloaded_pkg_path); + + if(!is_valid) { + result_str = pm_result_get_install(downloaded_pkg_path, false, "HASH_CHECK_FAILED"); error = true; } + else { + ret = pm_installer_install( + downloaded_pkg_path, __pkg_install_result_callback, NULL); + + if (ret) { + /* TODO : Reasons should be redefined */ + result_str = pm_result_get_install(downloaded_pkg_path, false, "PKG_MANAGER_ERROR"); + pm_worker_report_result(result_str); + error = true; + } + } } + + } + else if (!strcmp(operation, "uninstall")) + { + /*Todo: pkg_name */ + char * pkg_name = "org.tizen.example.CustomRenderer.Tizen.Mobile"; + + ret = pm_uninstaller_uninstall( + pkg_name, __pkg_uninstall_result_callback, NULL); + + if (ret) { + result_str = pm_result_get_uninstall(pkg_name, false, "PKG_MANAGER_ERROR"); + pm_worker_report_result(result_str); + } + exit = false; + } + else if(!strcmp(operation, "package")) + { + pm_result_get_package_information(); + exit = true; + } + else if(!strcmp(operation, "application")) + { + pm_result_get_package_information(); + exit = true; } - if (metadata->url) { + if ( metadata != NULL && metadata->url) { free(metadata->url); metadata->url = NULL; } - if (metadata->hash) { + if ( metadata != NULL && metadata->hash) { free(metadata->hash); metadata->hash = NULL; } @@ -120,12 +170,12 @@ static void service_app_control(app_control_h app_control, void *data) if (result_str) free(result_str); - if (downloaded_pkg) { - free(downloaded_pkg); - downloaded_pkg = NULL; + if (downloaded_pkg_path) { + free(downloaded_pkg_path); + downloaded_pkg_path = NULL; } - if (error) + if (error || exit) service_app_exit(); return; } |