SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BASE} -Wall -fPIE")
INCLUDE_DIRECTORIES(${INCLUDE_DIR})
-FILE(GLOB SOURCE_FILES "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c" "${INCLUDE_DIR}/update-manager-*.h" "${INCLUDE_DIR}/update-manager-*.c")
+FILE(GLOB SOURCE_FILES
+ "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c"
+ "${SOURCE_DIR}/*/*.h" "${SOURCE_DIR}/*/*.c"
+ "${INCLUDE_DIR}/update-manager-*.h" "${INCLUDE_DIR}/update-manager-*.c"
+)
ADD_EXECUTABLE(${PKG_NAME} ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${PKG_NAME} ${${PKG_NAME}_LDFLAGS} "-ldl")
INSTALL(TARGETS ${PKG_NAME} DESTINATION bin)
\ No newline at end of file
+++ /dev/null
-#include "update-manager.h"
-
-void common_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype,
- const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data)
-{
- switch (state) {
- case STORAGE_STATE_UNMOUNTABLE:
- case STORAGE_STATE_MOUNTED_READ_ONLY:
- _D("Storage %d status : not mounted", storage_id);
- break;
- case STORAGE_STATE_MOUNTED:
- _I("Storage %d status : mounted", storage_id);
- fota_storage_checker_plug(storage_id, mount_path);
- break;
- case STORAGE_STATE_REMOVED:
- _I("Storage %d status : removed", storage_id);
- fota_storage_checker_unplug(storage_id, mount_path);
- break;
- default:
- _E("Unexpected state : %d", state);
- }
-}
-
-int common_storage_checker_init()
-{
- int ret = 0;
-
- _I("Start process to get storage status");
- ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback, NULL);
- if (ret == STORAGE_ERROR_NOT_SUPPORTED) {
- _I("External storage is not suppported, so local update will not be supported");
- }
- else if (ret != STORAGE_ERROR_NONE) {
- _E("storage_set_changed_cb failed : %d", ret);
- return -1;
- }
-
- return 0;
-}
-
-int common_storage_checker_fini()
-{
- int ret = 0;
-
- ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback);
- if (ret != STORAGE_ERROR_NONE) {
- _W("failed storage_unset_changed_cb : %d", ret);
- return -1;
- }
-
- return 0;
-}
--- /dev/null
+#include "../recovery/recovery-manager.h"
+#include "../update-manager.h"
+
+void common_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype,
+ const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data)
+{
+ switch (state) {
+ case STORAGE_STATE_UNMOUNTABLE:
+ case STORAGE_STATE_MOUNTED_READ_ONLY:
+ _D("Storage %d status : not mounted", storage_id);
+ break;
+ case STORAGE_STATE_MOUNTED:
+ _I("Storage %d status : mounted", storage_id);
+ fota_storage_checker_plug(storage_id, mount_path);
+ recovery_storage_checker_plug(storage_id, mount_path);
+ break;
+ case STORAGE_STATE_REMOVED:
+ _I("Storage %d status : removed", storage_id);
+ fota_storage_checker_unplug(storage_id, mount_path);
+ recovery_storage_checker_unplug(storage_id, mount_path);
+ break;
+ default:
+ _E("Unexpected state : %d", state);
+ }
+}
+
+int common_storage_checker_init()
+{
+ int ret = 0;
+
+ _I("Start process to get storage status");
+ ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback, NULL);
+ if (ret == STORAGE_ERROR_NOT_SUPPORTED) {
+ _I("External storage is not suppported, so local update will not be supported");
+ }
+ else if (ret != STORAGE_ERROR_NONE) {
+ _E("storage_set_changed_cb failed : %d", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+int common_storage_checker_fini()
+{
+ int ret = 0;
+
+ ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback);
+ if (ret != STORAGE_ERROR_NONE) {
+ _W("failed storage_unset_changed_cb : %d", ret);
+ return -1;
+ }
+
+ return 0;
+}
+++ /dev/null
-#include "update-manager.h"
-
-static int fota_storage_id = -1;
-
-int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
-{
- int status = 0;
- char *build_id = NULL;
- const gchar *folder_name = NULL;
- GFile *mount = NULL;
- GFileEnumerator *enumerator = NULL;
- GFileInfo *info = NULL;
- GError* error = NULL;
-
- mount = g_file_new_for_path(mount_path);
- enumerator = g_file_enumerate_children(mount, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
- if (enumerator == NULL) {
- _E("Failed to get enumerator : %s", error->message);
- g_clear_error(&error);
- status = -1;
- goto search_destroy;
- }
-
- build_id = fota_info_get_build_id();
- if (build_id == NULL) {
- _E("Failed to get build id");
- status = -1;
- goto search_destroy;
- }
-
- while ((info = g_file_enumerator_next_file(enumerator, NULL, NULL)) != NULL) {
- if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY)
- continue;
-
- folder_name = g_file_info_get_name(info);
- if (g_str_has_prefix(folder_name, build_id) == TRUE) {
- *delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL);
- break;
- }
-
- g_object_unref(info);
- }
-
- if (*delta_path != NULL) {
- _I("Success to find delta path : %s", *delta_path);
- } else {
- _I("Failed to find delta path with prefix %s", build_id);
- status = 1;
- }
-
-search_destroy:
- if (enumerator)
- g_object_unref(enumerator);
-
- if (info)
- g_object_unref(info);
-
- g_object_unref(mount);
-
- return status;
-}
-
-void fota_storage_checker_plug(int storage_id, const char *mount_path)
-{
- int ret = 0;
- gchar *delta_path = NULL;
-
- _I("Storage mounted with %s, start process to check local delta", mount_path);
- ret = fota_storage_search_delta_path(mount_path, &delta_path);
- if (ret != 0) {
- _E("Failed to find delta path : %d", ret);
- goto process_destroy;
- }
-
- ret = fota_controller_verify_delta(delta_path);
- if (ret != 0) {
- _E("Failed to verify delta : %d", ret);
- goto process_destroy;
- }
-
- ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
- if (ret < 0) {
- _E("Failed to add launch request : %d, key : %s, value : %s",
- ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
- }
- fota_storage_id = storage_id;
-
-process_destroy:
- g_free(delta_path);
-}
-
-void fota_storage_checker_unplug(int storage_id, const char *mount_path)
-{
- int ret = 0;
- if (storage_id == fota_storage_id) {
- ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
- if (ret < 0) {
- _E("Failed to add launch request : %d, key : %s, value : %s",
- ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
- }
- fota_storage_id = -1;
- }
-}
--- /dev/null
+#include "../update-manager.h"
+
+static int fota_storage_id = -1;
+
+int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
+{
+ int status = 0;
+ char *build_id = NULL;
+ const gchar *folder_name = NULL;
+ GFile *mount = NULL;
+ GFileEnumerator *enumerator = NULL;
+ GFileInfo *info = NULL;
+ GError* error = NULL;
+
+ mount = g_file_new_for_path(mount_path);
+ enumerator = g_file_enumerate_children(mount, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
+ if (enumerator == NULL) {
+ _E("Failed to get enumerator : %s", error->message);
+ g_clear_error(&error);
+ status = -1;
+ goto search_destroy;
+ }
+
+ build_id = fota_info_get_build_id();
+ if (build_id == NULL) {
+ _E("Failed to get build id");
+ status = -1;
+ goto search_destroy;
+ }
+
+ while ((info = g_file_enumerator_next_file(enumerator, NULL, NULL)) != NULL) {
+ if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY)
+ continue;
+
+ folder_name = g_file_info_get_name(info);
+ if (g_str_has_prefix(folder_name, build_id) == TRUE) {
+ *delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL);
+ break;
+ }
+
+ g_object_unref(info);
+ }
+
+ if (*delta_path != NULL) {
+ _I("Success to find delta path : %s", *delta_path);
+ } else {
+ _I("Failed to find delta path with prefix %s", build_id);
+ status = 1;
+ }
+
+search_destroy:
+ if (enumerator)
+ g_object_unref(enumerator);
+
+ if (info)
+ g_object_unref(info);
+
+ g_object_unref(mount);
+
+ return status;
+}
+
+void fota_storage_checker_plug(int storage_id, const char *mount_path)
+{
+ int ret = 0;
+ gchar *delta_path = NULL;
+
+ _I("Storage mounted with %s, start process to check local delta", mount_path);
+ ret = fota_storage_search_delta_path(mount_path, &delta_path);
+ if (ret != 0) {
+ _E("Failed to find delta path : %d", ret);
+ goto process_destroy;
+ }
+
+ ret = fota_controller_verify_delta(delta_path);
+ if (ret != 0) {
+ _E("Failed to verify delta : %d", ret);
+ goto process_destroy;
+ }
+
+ ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
+ if (ret < 0) {
+ _E("Failed to add launch request : %d, key : %s, value : %s",
+ ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
+ }
+ fota_storage_id = storage_id;
+
+process_destroy:
+ g_free(delta_path);
+}
+
+void fota_storage_checker_unplug(int storage_id, const char *mount_path)
+{
+ int ret = 0;
+ if (storage_id == fota_storage_id) {
+ ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
+ if (ret < 0) {
+ _E("Failed to add launch request : %d, key : %s, value : %s",
+ ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
+ }
+ fota_storage_id = -1;
+ }
+}
+#include "recovery/recovery-manager.h"
#include "update-manager.h"
int main(int argc, char *argv[])
--- /dev/null
+#ifndef __RECOVERY_MANAGER_H__
+#define __RECOVERY_MANAGER_H__
+
+#include <dlog.h>
+
+/* Log */
+#define RECOVERY_LOG_TAG "RECOVERY_MANAGER"
+
+#define _RLOGD(fmt, arg...) SLOG(LOG_INFO, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGI(fmt, arg...) SLOG(LOG_INFO, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGW(fmt, arg...) SLOG(LOG_WARN, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGE(fmt, arg...) SLOG(LOG_ERROR, RECOVERY_LOG_TAG, fmt, ##arg)
+
+/* Constant */
+#define RECOVERY_CLIENT_METADATA_KEY "tizen-recovery-manager"
+#define RECOVERY_CLIENT_METADATA_VALUE "client"
+
+#define RECOVERY_IMAGE_FILE "tizen-recovery.img"
+
+/* Function */
+void recovery_storage_checker_plug(int, const char *);
+void recovery_storage_checker_unplug(int, const char *);
+
+#endif /* __RECOVERY_MANAGER_H__ */
--- /dev/null
+#include "recovery-manager.h"
+#include "../update-manager.h"
+
+static int recovery_storage_id = -1;
+
+int recovery_storage_search_image(const gchar *image_path)
+{
+ if (g_file_test(image_path, G_FILE_TEST_EXISTS)) {
+ _RLOGI("Found image in %s, start process to verify", image_path);
+ return 0;
+ } else {
+ _RLOGI("Not found image in %s", image_path);
+ return -1;
+ }
+}
+
+void recovery_storage_checker_plug(int storage_id, const char *mount_path)
+{
+ int ret = 0;
+ gchar *image_path = NULL;
+
+ _RLOGI("Storage mounted with %s, start process to check recovery image", mount_path);
+ image_path = g_strjoin("/", mount_path, RECOVERY_IMAGE_FILE, NULL);
+
+ ret = recovery_storage_search_image(image_path);
+ if (ret != 0) {
+ _RLOGE("Failed to find delta path : %d", ret);
+ goto plug_destroy;
+ }
+
+plug_destroy:
+ g_free(image_path);
+}
+
+void recovery_storage_checker_unplug(int storage_id, const char *mount_path)
+{
+ recovery_storage_id = -1;
+}